Package test_suite :: Package system_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.relax_disp

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006-2015 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2009 Sebastien Morin                                          # 
   5  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
   6  #                                                                             # 
   7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   8  #                                                                             # 
   9  # This program is free software: you can redistribute it and/or modify        # 
  10  # it under the terms of the GNU General Public License as published by        # 
  11  # the Free Software Foundation, either version 3 of the License, or           # 
  12  # (at your option) any later version.                                         # 
  13  #                                                                             # 
  14  # This program is distributed in the hope that it will be useful,             # 
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  17  # GNU General Public License for more details.                                # 
  18  #                                                                             # 
  19  # You should have received a copy of the GNU General Public License           # 
  20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  21  #                                                                             # 
  22  ############################################################################### 
  23   
  24  # Python module imports. 
  25  from os import F_OK, access, getcwd, path, sep 
  26  from numpy import array, asarray, exp, median, inf, linspace, log, save, std, sum, zeros 
  27  from minfx.generic import generic_minimise 
  28  from random import gauss 
  29  import re, math 
  30  from sys import version_info 
  31  from tempfile import mkdtemp, NamedTemporaryFile 
  32   
  33   
  34  # relax module imports. 
  35  from auto_analyses import relax_disp 
  36  from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep 
  37  from data_store import Relax_data_store; ds = Relax_data_store() 
  38  import dep_check 
  39  from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_ANALYTIC_CPMG, MODEL_LIST_FULL, MODEL_LIST_NUMERIC_CPMG, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_NS_R1RHO_3SITE, MODEL_NS_R1RHO_3SITE_LINEAR, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  40  from lib.errors import RelaxError 
  41  from lib.io import extract_data, get_file_path, open_read_file 
  42  from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file 
  43  from pipe_control.mol_res_spin import display_spin, generate_spin_string, return_spin, spin_loop 
  44  from pipe_control.minimise import assemble_scaling_matrix 
  45  from pipe_control.pipes import display 
  46  from specific_analyses.relax_disp.checks import check_missing_r1 
  47  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  48  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, has_r1rho_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_exp_frq_offset_point_time, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  49  from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF 
  50  from specific_analyses.relax_disp.model import models_info, nesting_param 
  51  from specific_analyses.relax_disp.parameters import linear_constraints 
  52  from status import Status; status = Status() 
  53  from target_functions.relax_fit_wrapper import Relax_fit_opt 
  54  from test_suite.system_tests.base_classes import SystemTestCase 
  55   
  56   
57 -class Relax_disp(SystemTestCase):
58 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 59
60 - def __init__(self, methodName='runTest'):
61 """Skip certain tests if the C modules are non-functional. 62 63 @keyword methodName: The name of the test. 64 @type methodName: str 65 """ 66 67 # Execute the base class method. 68 super(Relax_disp, self).__init__(methodName) 69 70 # Tests to skip. 71 blacklist = [ 72 'test_m61b_data_to_m61b' 73 ] 74 if methodName in blacklist: 75 status.skipped_tests.append([methodName, None, self._skip_type]) 76 77 # Missing module. 78 if not dep_check.C_module_exp_fn: 79 # The list of tests to skip. 80 to_skip = [ 81 "test_bug_atul_srivastava", 82 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 83 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 84 "test_estimate_r2eff_err", 85 "test_estimate_r2eff_err_auto", 86 "test_estimate_r2eff_err_methods", 87 "test_finite_value", 88 "test_exp_fit", 89 "test_m61_exp_data_to_m61", 90 "test_r1rho_kjaergaard_auto", 91 "test_r1rho_kjaergaard_auto_check_graphs", 92 "test_r1rho_kjaergaard_man", 93 "test_r1rho_kjaergaard_missing_r1", 94 "test_value_write_calc_rotating_frame_params_auto_analysis" 95 ] 96 97 # Store in the status object. 98 if methodName in to_skip: 99 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 100 101 # If not scipy.optimize.leastsq. 102 if not dep_check.scipy_module: 103 # The list of tests to skip. 104 to_skip = [ 105 "test_estimate_r2eff_err_methods" 106 ] 107 108 # Store in the status object. 109 if methodName in to_skip: 110 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type]) 111 112 # If not NMRPipe showApod program in PATH. 113 if not dep_check.showApod_software: 114 # The list of tests to skip. 115 to_skip = [ 116 "test_show_apod_extract", 117 "test_show_apod_rmsd", 118 "test_show_apod_rmsd_to_file", 119 "test_show_apod_rmsd_dir_to_files" 120 ] 121 122 # Store in the status object. 123 if methodName in to_skip: 124 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type]) 125 126 # If not matplotlib module 127 if not dep_check.matplotlib_module: 128 # The list of tests to skip. 129 to_skip = [ 130 "test_repeat_cpmg" 131 ] 132 133 # Store in the status object. 134 if methodName in to_skip: 135 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
136 137
138 - def setUp(self):
139 """Set up for all the functional tests.""" 140 141 # Create the data pipe. 142 self.interpreter.pipe.create('relax_disp', 'relax_disp') 143 144 # Create a temporary directory for dumping files. 145 ds.tmpdir = mkdtemp() 146 self.tmpdir = ds.tmpdir
147 148
149 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
150 """Setup data for the catch of U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models. 151 152 @keyword folder: The name of the folder for the test data. 153 @type folder: str 154 @keyword model_analyse: The name of the model which will be tested. 155 @type model_analyse: str 156 """ 157 158 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 159 160 # Data. 161 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 162 163 ## Experiments 164 # Exp 1 165 sfrq_1 = 500.0*1E6 166 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 167 time_T2_1 = 0.05 168 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 169 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 170 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 171 r2eff_errs_1 = [0.0] * len(ncycs_1) 172 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 173 174 sfrq_2 = 600.0*1E6 175 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 176 time_T2_2 = 0.06 177 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 178 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 179 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 180 r2eff_errs_2 = [0.0] * len(ncycs_2) 181 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 182 183 sfrq_3 = 700.0*1E6 184 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 185 time_T2_3 = 0.07 186 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 187 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 188 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 189 r2eff_errs_3 = [0.0] * len(ncycs_3) 190 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 191 192 # Collect all exps 193 exps = [exp_1, exp_2, exp_3] 194 195 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3] 196 dw_arr = [1.0, 2.0, 3.0, 4.0] 197 pA_arr = [0.9] 198 kex_arr = [1000.] 199 200 spins = [ 201 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}], 202 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}], 203 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}], 204 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}], 205 ] 206 207 # Create the data pipe. 208 pipe_name = 'base pipe' 209 pipe_type = 'relax_disp' 210 pipe_bundle = 'relax_disp' 211 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 212 213 # Generate the sequence. 214 for res_name, res_num, spin_name, params in spins: 215 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 216 217 # Set isotope 218 self.interpreter.spin.isotope('15N', spin_id='@N') 219 220 # Now loop over the experiments, to set the variables in relax. 221 exp_ids = [] 222 for exp_i in exps: 223 sfrq, time_T2, ncycs, r2eff_errs = exp_i 224 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 225 exp_ids.append(exp_id) 226 227 ids = [] 228 for ncyc in ncycs: 229 nu_cpmg = ncyc / time_T2 230 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 231 ids.append(cur_id) 232 233 # Set the spectrometer frequency. 234 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 235 236 # Set the experiment type. 237 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 238 239 # Set the relaxation dispersion CPMG constant time delay T (in s). 240 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 241 242 # Set the relaxation dispersion CPMG frequencies. 243 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 244 245 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 246 247 ### Now do fitting. 248 # Change pipe. 249 250 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 251 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 252 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 253 254 # Now read data in. 255 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 256 exp_id = exp_ids[mi] 257 exp_i = exps[mi] 258 sfrq, time_T2, ncycs, r2eff_errs = exp_i 259 260 # Then loop over the spins. 261 for res_name, res_num, spin_name, params in spins: 262 cur_spin_id = ":%i@%s"%(res_num, spin_name) 263 264 # Define file name 265 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 266 267 # Read in the R2eff file to put into spin structure. 268 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3) 269 270 # Then select model. 271 self.interpreter.relax_disp.select_model(model=model_analyse) 272 273 # Then cluster 274 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 275 276 # Grid search 277 low_arr = R20 + dw_arr + pA_arr + kex_arr 278 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 279 280 # Then loop over the defined spins and read the parameters. 281 for i in range(len(spins)): 282 res_name, res_num, spin_name, params = spins[i] 283 cur_spin_id = ":%i@%s"%(res_num, spin_name) 284 cur_spin = return_spin(cur_spin_id) 285 286 for mo_param in cur_spin.params: 287 print(mo_param) 288 # The R2 is a dictionary, depending on spectrometer frequency. 289 if isinstance(getattr(cur_spin, mo_param), dict): 290 for key, val in list(getattr(cur_spin, mo_param).items()): 291 should_be = params[mo_param][key] 292 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 293 self.assertAlmostEqual(val, should_be) 294 else: 295 should_be = float(params[mo_param]) 296 val = getattr(cur_spin, mo_param) 297 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 298 self.assertAlmostEqual(val, should_be) 299 300 # Test chi2. 301 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 302 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
303 304
305 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
306 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 307 308 # The path to the data files. 309 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 310 311 # Set pipe name, bundle and type. 312 ds.pipe_name = 'base pipe' 313 ds.pipe_bundle = 'relax_disp' 314 ds.pipe_type = 'relax_disp' 315 316 # Create the data pipe. 317 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 318 319 # Read the spins. 320 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 321 322 # Name the isotope for field strength scaling. 323 self.interpreter.spin.isotope(isotope='15N') 324 325 # Set number of experiments to be used. 326 NR_exp = 70 327 328 # Load the experiments settings file. 329 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 330 expfileslines = expfile.readlines()[:NR_exp] 331 expfile.close() 332 333 # In MHz 334 yOBS = 81.050 335 # In ppm 336 yCAR = 118.078 337 centerPPM_N15 = yCAR 338 339 ## Read the chemical shift data. 340 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 341 342 # The lock power to field, has been found in an calibration experiment. 343 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 344 345 # Apply spectra settings. 346 # Count settings 347 j = 0 348 for i in range(len(expfileslines)): 349 line = expfileslines[i] 350 if line[0] == "#": 351 continue 352 else: 353 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 354 DIRN = line.split()[0] 355 I = int(line.split()[1]) 356 deltadof2 = line.split()[2] 357 dpwr2slock = line.split()[3] 358 ncyc = int(line.split()[4]) 359 trim = float(line.split()[5]) 360 ss = int(line.split()[6]) 361 set_sfrq = float(line.split()[7]) 362 apod_rmsd = float(line.split()[8]) 363 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 364 365 # Calculate spin_lock time 366 time_sl = 2*ncyc*trim 367 368 # Define file name for peak list. 369 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 370 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 371 372 # Load the peak intensities. 373 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 374 375 # Set the peak intensity errors, as defined as the baseplane RMSD. 376 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 377 378 # Set the relaxation dispersion experiment type. 379 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 380 381 # Set The spin-lock field strength, nu1, in Hz 382 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 383 384 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 385 frq_N15_Hz = yOBS * 1E6 386 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 387 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 388 389 # Set The spin-lock offset, omega_rf, in ppm. 390 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 391 392 # Set the relaxation times (in s). 393 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 394 395 # Set the spectrometer frequency. 396 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 397 398 # Add to counter 399 j += 1 400 401 402 print("Testing the number of settings") 403 print("Number of settings iterations is: %s. Number of cdp.exp_type is: %s"%(i, len(cdp.exp_type))) 404 self.assertEqual(70, len(expfileslines)) 405 self.assertEqual(69, j) 406 self.assertEqual(69, len(cdp.exp_type)) 407 408 # Cluster spins 409 for curspin in cluster_ids: 410 print("Adding spin %s to cluster"%curspin) 411 self.interpreter.relax_disp.cluster('model_cluster', curspin) 412 413 # De-select for analysis those spins who have not been clustered 414 for free_spin in cdp.clustering['free spins']: 415 print("Deselecting free spin %s"%free_spin) 416 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 417 418 419 #Paper reference values 420 # Resi Resn R1_rad_s R1err_rad_s R2_rad_s R2err_rad_s kEX_rad_s kEXerr_rad_s phi_rad2_s2 phierr_rad2_s2 phi_ppm2 phierr_ppm2 421 # Scaling rad2_s2 to ppm2: scaling_rad2_s2 = frequency_to_ppm(frq=1/(2*pi), B0=cdp.spectrometer_frq_list[0], isotope='15N')**2 = 3.85167990165e-06 422 ds.ref = dict() 423 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 424 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 425 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 426 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 427 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 428 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 429 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 430 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 431 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 432 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 433 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 434 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 435 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 436 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 437 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 438 439 ds.guess = dict() 440 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 441 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 442 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 443 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 444 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 445 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 446 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 447 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 448 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 449 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 450 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 451 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 452 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 453 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 454 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 455 456 # Assign guess values. 457 for spin, spin_id in spin_loop(return_id=True): 458 if spin_id in cluster_ids: 459 print("spin_id %s in cluster ids"%(spin_id)) 460 spin.kex = ds.guess[spin_id][6] 461 spin.phi_ex = ds.guess[spin_id][10] 462 else: 463 print("spin_id %s NOT in cluster ids"%(spin_id)) 464 465 if read_R1: 466 # Read the R1 data 467 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
468 469
470 - def setup_hansen_cpmg_data(self, model=None):
471 """Set up the data for the test_hansen_cpmg_data_*() system tests. 472 473 @keyword model: The name of the model which will be tested. 474 @type model: str 475 """ 476 477 # Create the data pipe and load the base data. 478 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 479 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 480 self.interpreter.results.read(data_path+sep+'base_pipe') 481 self.interpreter.deselect.spin(':4') 482 483 # Set the nuclear isotope data. 484 self.interpreter.spin.isotope('15N') 485 486 # Create the R2eff data pipe and load the results. 487 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 488 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 489 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 490 self.interpreter.deselect.spin(':4') 491 492 # The model data pipe. 493 pipe_name = "%s - relax_disp" % model 494 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 495 self.interpreter.pipe.switch(pipe_name=pipe_name) 496 497 # Set the model. 498 self.interpreter.relax_disp.select_model(model=model) 499 500 # Copy the data. 501 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
502 503
504 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
505 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 506 507 @keyword model: The name of the model which will be tested. 508 @type model: str 509 """ 510 511 # Create the data pipe and load the base data. 512 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 513 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 514 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 515 516 # Create the R2eff data pipe and load the results. 517 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 518 self.interpreter.pipe.switch(pipe_name='R2eff') 519 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 520 521 # The model data pipe. 522 pipe_name = "%s - relax_disp" % model 523 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 524 self.interpreter.pipe.switch(pipe_name=pipe_name) 525 526 # Set the model. 527 self.interpreter.relax_disp.select_model(model=model) 528 529 # Copy the data. 530 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
531 532
533 - def setup_korzhnev_2005_data(self, data_list=[]):
534 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 535 536 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 537 538 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}). 539 540 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 541 542 543 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 544 @type data_list: list of str 545 """ 546 547 # Create the data pipe and load the base data. 548 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 549 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 550 551 # Create the spin system. 552 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 553 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 554 self.interpreter.spin.element('H', spin_id='@H') 555 self.interpreter.spin.element('N', spin_id='@N') 556 self.interpreter.spin.isotope('1H', spin_id='@H') 557 self.interpreter.spin.isotope('15N', spin_id='@N') 558 559 # Define the magnetic dipole-dipole relaxation interaction. 560 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 561 562 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 563 data = [ 564 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 565 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 566 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 567 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 568 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 569 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 570 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 571 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 572 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 573 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 574 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 575 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 576 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 577 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 578 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 579 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 580 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 581 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 582 ] 583 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 584 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 585 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 586 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 587 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0] 588 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 589 590 # Loop over the files, reading in the data. 591 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 592 # Skip undesired data. 593 if data_type not in data_list: 594 continue 595 596 # Alias the CPMG frequencies. 597 if data_type == 'SQ': 598 cpmg_frqs = cpmg_frqs_sq 599 elif data_type == '1H SQ': 600 cpmg_frqs = cpmg_frqs_1h_sq 601 elif data_type == 'DQ': 602 cpmg_frqs = cpmg_frqs_dq 603 elif data_type == 'ZQ': 604 cpmg_frqs = cpmg_frqs_zq 605 elif data_type == '1H MQ': 606 cpmg_frqs = cpmg_frqs_1h_mq 607 elif data_type == 'MQ': 608 cpmg_frqs = cpmg_frqs_mq 609 610 # Loop over each CPMG frequency. 611 for cpmg_frq in cpmg_frqs: 612 # The id. 613 new_id = "%s_%s" % (id, cpmg_frq) 614 615 # Set the NMR field strength. 616 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 617 618 # Set the relaxation dispersion experiment type. 619 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 620 621 # Relaxation dispersion CPMG constant time delay T (in s). 622 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 623 624 # Set the CPMG frequency. 625 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 626 627 # Read the R2eff data. 628 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 629 630 # Change the model. 631 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
632 633
634 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
635 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 636 637 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 638 'SOD1-WT' CPMG data to the CR72 dispersion model. 639 640 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 641 Data is for experiment at 25 degree Celcius. 642 """ 643 644 # Create the data pipe and load the base data. 645 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 646 647 # Set experiment settings. sfrq, time_T2, ncyc 648 Exps = [ 649 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ], 650 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ] 651 652 # Create base pipe 653 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 654 655 # Loop throug experiments 656 id_lists = [] 657 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 658 # Read spins 659 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 660 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 661 662 # Make spectrum id list 663 id_list = list(key+str(i) for i in range(len(ncycs))) 664 id_lists.append(id_list) 665 666 # Read intensities 667 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) ) 668 669 # Loop over experiments 670 for i in range(len(ncycs)): 671 ncyc = ncycs[i] 672 vcpmg = ncyc/time_T2 673 674 # Test if spectrum is a reference 675 if float(vcpmg) == 0.0: 676 vcpmg = None 677 else: 678 vcpmg = round(float(vcpmg), 3) 679 680 # Set current id 681 current_id = id_list[i] 682 683 # Set the current experiment type. 684 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 685 686 # Set the NMR field strength of the spectrum. 687 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 688 689 # Relaxation dispersion CPMG constant time delay T (in s). 690 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 691 692 # Set the relaxation dispersion CPMG frequencies. 693 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 694 695 # Define replicated 696 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 697 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 698 699 # Perform error analysis 700 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 701 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 702 703 # Define isotope 704 self.interpreter.spin.isotope(isotope='15N') 705 706 ############# 707 708 # Define the 64 residues which was used for Global fitting 709 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 710 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 711 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 712 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 713 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 714 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 715 716 # Test number of global 717 self.assertEqual(64, len(glob_assn )) 718 719 ## Turn assignments into relax spin ids. 720 # Define regular expression search 721 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 722 723 # Create list to hold regular expression search 724 relax_glob_ids = [] 725 726 # Loop over assignments 727 for assn in glob_assn: 728 # Make match for the regular search 729 m = r.match(assn) 730 # Convert to relax spin string 731 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 732 733 # Save the relax spin string and the regular search 734 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 735 736 ############# Deselect all spins, and select few spins 737 738 ## Deselect all spins, and select a few for analysis 739 self.interpreter.deselect.all() 740 741 # Select few spins 742 for i in select_spin_index: 743 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 744 745 ############## 746 747 # Prepare for R2eff calculation 748 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 749 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 750 751 # Select model for points calculation 752 MODEL = "R2eff" 753 self.interpreter.relax_disp.select_model(model=MODEL) 754 # Calculate R2eff values 755 self.interpreter.minimise.calculate(verbosity=1)
756 757
758 - def setup_missing_r1_spins(self):
759 """Function for setting up a few spins for the given pipe.""" 760 761 # Path to file. 762 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 763 764 # File with spins. 765 file = open(data_path+sep+'R1_fitted_values.txt') 766 lines = file.readlines() 767 file.close() 768 769 for i, line in enumerate(lines): 770 # Make the string test 771 line_split = line.split() 772 773 if line_split[0] == "#": 774 continue 775 776 mol_name = line_split[0] 777 mol_name = None 778 res_num = int(line_split[1]) 779 res_name = line_split[2] 780 spin_num = line_split[3] 781 spin_num = None 782 spin_name = line_split[4] 783 784 # Create the spin. 785 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
786 787
788 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
789 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 790 791 # Reset. 792 self.interpreter.reset() 793 794 # Create the data pipe and load the base data. 795 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 796 self.interpreter.state.load(data_path+sep+'r2eff_values') 797 798 # The model data pipe. 799 model = 'NS R1rho 2-site' 800 pipe_name = "%s - relax_disp" % model 801 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 802 self.interpreter.pipe.switch(pipe_name=pipe_name) 803 804 # Set the model. 805 self.interpreter.relax_disp.select_model(model=model) 806 807 # Copy the data. 808 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 809 810 # Alias the spins. 811 spin1 = cdp.mol[0].res[0].spin[0] 812 spin2 = cdp.mol[0].res[1].spin[0] 813 814 # The R20 keys. 815 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 816 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 817 818 # Set the initial parameter values. 819 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 820 spin1.pA = 0.779782428085762 821 spin1.dw = 7.57855284496424 822 spin1.kex = 1116.7911285203 823 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 824 spin2.pA = 0.826666229688602 825 spin2.dw = 9.5732624231366 826 spin2.kex = 1380.46162655657 827 828 # Test the values when clustering. 829 if clustering: 830 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 831 832 # Low precision optimisation. 833 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 834 835 # Printout. 836 print("\n\nOptimised parameters:\n") 837 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 838 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 839 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 840 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 841 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 842 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 843 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
844 845
846 - def test_baldwin_synthetic(self):
847 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 848 849 Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 850 851 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s. 852 """ 853 854 # The path to the data files. 855 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 856 857 # Create pipe 858 pipe_name = 'base pipe' 859 pipe_type = 'relax_disp' 860 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 861 862 # Create base pipe 863 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 864 865 # Generate the sequence. 866 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 867 868 # Define the isotope. 869 self.interpreter.spin.isotope('1H', spin_id='@H') 870 871 # Build the experiment IDs. 872 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 873 ncycs = [2, 4, 8, 10, 20, 40, 500] 874 ids = [] 875 for ncyc in ncycs: 876 ids.append('CPMG_%s' % ncyc) 877 878 print("\n\nThe experiment IDs are %s." % ids) 879 880 # Set up the metadata for the experiments. 881 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 882 sfrq = 200. * 1E6 883 884 # Total time of CPMG block. 885 Trelax = 0.04 886 887 # First set the 888 for i in range(len(ids)): 889 id = ids[i] 890 # Set the spectrometer frequency. 891 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 892 893 # Set the experiment type. 894 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 895 896 # Set the relaxation dispersion CPMG constant time delay T (in s). 897 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 898 899 # Set the relaxation dispersion CPMG frequencies. 900 ncyc = ncycs[i] 901 nu_cpmg = ncyc / Trelax 902 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 903 904 # Prepare for R2eff reading. 905 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 906 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 907 908 # Try reading the R2eff file. 909 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 910 911 # Check the global data. 912 data = [ 913 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 914 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 915 ['dispersion_points', len(ncycs)], 916 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 917 ['exp_type_list', ['SQ CPMG']], 918 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 919 ['spectrometer_frq_count', 1], 920 ['spectrometer_frq_list', [sfrq]], 921 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 922 ] 923 for name, value in data: 924 # Does it exist? 925 self.assert_(hasattr(cdp, name)) 926 927 # Check the object. 928 obj = getattr(cdp, name) 929 if not isinstance(data, dict): 930 self.assertEqual(obj, value) 931 932 # Check the global dictionary data. 933 else: 934 for id in ids: 935 self.assertEqual(obj[id], value[id]) 936 937 # Check the spin data. 938 n_data = [ 939 [ 50.000000, 10.367900, 0.1], 940 [ 100.000000, 10.146849, 0.1], 941 [ 200.000000, 9.765987, 0.1], 942 [ 250.000000, 9.409789, 0.1], 943 [ 500.000000, 5.829819, 0.1], 944 [ 1000.000000, 3.191928, 0.1], 945 [ 12500.000000, 2.008231, 0.1] 946 ] 947 for disp_point, value, error in n_data: 948 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 949 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 950 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 951 952 # Generate r20 key. 953 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 954 955 ## Now prepare for MODEL calculation. 956 MODEL = "B14" 957 958 # Change pipe. 959 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 960 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 961 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 962 963 # Then select model. 964 self.interpreter.relax_disp.select_model(model=MODEL) 965 966 # Store grid and minimisations results. 967 grid_results = [] 968 mini_results = [] 969 970 # The grid search size (the number of increments per dimension). 971 # If None, use the default values. 972 #GRID = None 973 GRID = 13 974 # Perform Grid Search. 975 if GRID: 976 # Set the R20 parameters in the default grid search using the minimum R2eff value. 977 # This speeds it up considerably. 978 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 979 980 # Then do grid search. 981 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 982 983 # If no Grid search, set the default values. 984 else: 985 for param in MODEL_PARAMS[MODEL]: 986 self.interpreter.value.set(param=param, index=None) 987 # Do a grid search, which will store the chi2 value. 988 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 989 990 # Store result. 991 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 992 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 993 994 ## Now do minimisation. 995 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 996 set_func_tol = 1e-10 997 set_max_iter = 1000 998 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 999 1000 # Store result. 1001 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1002 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1003 1004 # Print results. 1005 for i in range(len(grid_results)): 1006 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1007 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1008 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1009 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1010 1011 # Reference values from Baldwin.py. 1012 # Exchange rate = k+ + k- (s-1) 1013 kex = 1000. 1014 # Fractional population of excited state k+/kex 1015 pb = 0.01 1016 # deltaOmega in ppm 1017 dw_ppm = 2. 1018 #relaxation rate of ground (s-1) 1019 R2g = 2. 1020 #relaxation rate of excited (s-1) 1021 R2e = 2. 1022 1023 # Test the parameters which created the data. 1024 # This is for the 1H spin. 1025 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 1026 1027 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1028 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1029 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1030 1031
1033 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 1034 1035 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}. 1036 """ 1037 1038 # The path to the data files. 1039 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1040 1041 # Create pipe 1042 pipe_name = 'base pipe' 1043 pipe_type = 'relax_disp' 1044 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1045 1046 # Create base pipe 1047 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1048 1049 # Generate the sequence. 1050 # Generate both a 1H spin, and 15N spin. 1051 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1052 1053 # Define the isotope. 1054 self.interpreter.spin.isotope('1H', spin_id='@H') 1055 1056 # Build the experiment IDs. 1057 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1058 ncycs = [2, 4, 8, 10, 20, 40, 500] 1059 ids = [] 1060 for ncyc in ncycs: 1061 ids.append('CPMG_%s' % ncyc) 1062 1063 print("\n\nThe experiment IDs are %s." % ids) 1064 1065 # Set up the metadata for the experiments. 1066 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1067 sfrq = 200. * 1E6 1068 1069 # Total time of CPMG block. 1070 Trelax = 0.04 1071 1072 # First set the 1073 for i in range(len(ids)): 1074 id = ids[i] 1075 # Set the spectrometer frequency. 1076 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1077 1078 # Set the experiment type. 1079 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1080 1081 # Set the relaxation dispersion CPMG constant time delay T (in s). 1082 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1083 1084 # Set the relaxation dispersion CPMG frequencies. 1085 ncyc = ncycs[i] 1086 nu_cpmg = ncyc / Trelax 1087 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1088 1089 # Prepare for R2eff reading. 1090 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1091 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1092 1093 # Try reading the R2eff file. 1094 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 1095 1096 # Check the global data. 1097 data = [ 1098 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 1099 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1100 ['dispersion_points', len(ncycs)], 1101 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 1102 ['exp_type_list', ['SQ CPMG']], 1103 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 1104 ['spectrometer_frq_count', 1], 1105 ['spectrometer_frq_list', [sfrq]], 1106 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1107 ] 1108 for name, value in data: 1109 # Does it exist? 1110 self.assert_(hasattr(cdp, name)) 1111 1112 # Check the object. 1113 obj = getattr(cdp, name) 1114 if not isinstance(data, dict): 1115 self.assertEqual(obj, value) 1116 1117 # Check the global dictionary data. 1118 else: 1119 for id in ids: 1120 self.assertEqual(obj[id], value[id]) 1121 1122 # Check the spin data. 1123 n_data = [ 1124 [ 50.000000, 10.286255, 0.1], 1125 [ 100.000000, 10.073083, 0.1], 1126 [ 200.000000, 9.692746, 0.1], 1127 [ 250.000000, 9.382441, 0.1], 1128 [ 500.000000, 6.312396, 0.1], 1129 [ 1000.000000, 3.957029, 0.1], 1130 [ 12500.000000, 2.880420, 0.1] 1131 ] 1132 for disp_point, value, error in n_data: 1133 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1134 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1135 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1136 1137 # Generate r20 key. 1138 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1139 1140 ## Now prepare for MODEL calculation. 1141 MODEL = "B14 full" 1142 1143 # Change pipe. 1144 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1145 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1146 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1147 1148 # Then select model. 1149 self.interpreter.relax_disp.select_model(model=MODEL) 1150 1151 # Store grid and minimisations results. 1152 grid_results = [] 1153 mini_results = [] 1154 clust_results = [] 1155 1156 # The grid search size (the number of increments per dimension). 1157 # If None, use the default values. 1158 #GRID = None 1159 GRID = 13 1160 # Perform Grid Search. 1161 if GRID: 1162 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1163 # This speeds it up considerably. 1164 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1165 1166 # Then do grid search. 1167 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1168 1169 # If no Grid search, set the default values. 1170 else: 1171 for param in MODEL_PARAMS[MODEL]: 1172 self.interpreter.value.set(param=param, index=None) 1173 # Do a grid search, which will store the chi2 value. 1174 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1175 1176 # Store result. 1177 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1178 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1179 1180 ## Now do minimisation. 1181 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1182 set_func_tol = 1e-11 1183 set_max_iter = 10000 1184 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1185 1186 # Store result. 1187 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1188 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1189 1190 print("\n# Now print before and after minimisation-\n") 1191 1192 # Print results. 1193 for i in range(len(grid_results)): 1194 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1195 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1196 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1197 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1198 1199 # Reference values from Baldwin.py. 1200 # Exchange rate = k+ + k- (s-1) 1201 kex = 1000. 1202 # Fractional population of excited state k+/kex 1203 pb = 0.01 1204 # deltaOmega in ppm 1205 dw_ppm = 2. 1206 #relaxation rate of ground (s-1) 1207 R2g = 2. 1208 #relaxation rate of excited (s-1) 1209 R2e = 100. 1210 1211 # Test the parameters which created the data. 1212 # This is for the 1H spin. 1213 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3) 1214 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3) 1215 1216 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1217 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1218 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1219 1220
1221 - def x_test_bmrb_sub_cpmg(self):
1222 """U{Task #7858: <https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB. 1223 This uses CPMG data from: 1224 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE. 1225 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 1226 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886 1227 """ 1228 1229 # Define path to data 1230 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 1231 1232 # Read data. 1233 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 1234 1235 # Set element 1236 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False) 1237 #self.interpreter.spin.isotope(isotope='15N', spin_id=':*@N', force=False) 1238 # Rename molecule from None to 'HEWL' 1239 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True) 1240 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False) 1241 1242 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1243 print(spin_id) 1244 if resn == 'C': 1245 print(resi, resn) 1246 1247 # Select the thiol state of the system. 1248 # 'all disulfide bound', 'all free', 'all other bound', 'disulfide and other bound', 'free and disulfide bound', 'free and other bound', 'free disulfide and other bound', 'not available', 'not present', 'not reported', 'unknown' 1249 self.interpreter.bmrb.thiol_state(state='not reported') 1250 1251 # relax_data.temp_calibration(ri_id=None, method=None) 1252 1253 # Call display of bmrb. 1254 self.interpreter.bmrb.display()
1255 1256
1258 """U{Bug #21081<https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1259 1260 # Clear the data store. 1261 self.interpreter.reset() 1262 1263 # Load the state. 1264 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1265 self.interpreter.state.load(state, force=True) 1266 1267 # Model selection - to catch the failure. 1268 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1269 1270
1272 """U{Bug #21460<https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data.""" 1273 1274 # Clear the data store. 1275 self.interpreter.reset() 1276 1277 # Load the state. 1278 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1279 self.interpreter.state.load(state, force=True) 1280 1281 # Execute the auto-analysis (fast). 1282 relax_disp.Relax_disp.opt_func_tol = 1e-5 1283 relax_disp.Relax_disp.opt_max_iterations = 1000 1284 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1285 1286
1288 """U{Bug #21665<https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis.""" 1289 1290 # Clear the data store. 1291 self.interpreter.reset() 1292 1293 # Load the state. 1294 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1295 self.interpreter.state.load(state, force=True) 1296 1297 # Execute the auto-analysis (fast). 1298 relax_disp.Relax_disp.opt_func_tol = 1e-5 1299 relax_disp.Relax_disp.opt_max_iterations = 1000 1300 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1301 1302
1304 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using minimise.calculate().""" 1305 1306 # Clear the data store. 1307 self.interpreter.reset() 1308 1309 # Load the state. 1310 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1311 self.interpreter.state.load(state, force=True) 1312 1313 # Run the calculation. 1314 self.interpreter.minimise.calculate(verbosity=1)
1315 1316
1318 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times using auto_analysis.""" 1319 1320 # Clear the data store. 1321 self.interpreter.reset() 1322 1323 # Load the state. 1324 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1325 self.interpreter.state.load(state, force=True) 1326 1327 # Execute the auto-analysis (fast). 1328 relax_disp.Relax_disp.opt_func_tol = 1e-5 1329 relax_disp.Relax_disp.opt_max_iterations = 1000 1330 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1331 1332
1334 """Catch U{bug #21715<https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError.""" 1335 1336 # Clear the data store. 1337 self.interpreter.reset() 1338 1339 # Load the state. 1340 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1341 self.interpreter.state.load(state, force=True) 1342 1343 # Execute the auto-analysis (fast). 1344 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1345 relax_disp.Relax_disp.opt_func_tol = 1e-5 1346 relax_disp.Relax_disp.opt_max_iterations = 1000 1347 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=3, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1348 1349
1351 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered B14 full analysis.""" 1352 1353 # Base data setup. 1354 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1355 1356
1358 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered CR72 full analysis.""" 1359 1360 # Base data setup. 1361 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1362 1363
1365 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE 3D full analysis.""" 1366 1367 # Base data setup. 1368 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1369 1370
1372 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE STAR full analysis.""" 1373 1374 # Base data setup. 1375 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1376 1377
1379 """Catch U{bug #22146<https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis.""" 1380 1381 # Clear the data store. 1382 self.interpreter.reset() 1383 1384 # Load the state. 1385 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2' 1386 self.interpreter.state.load(state, force=True) 1387 1388 param = 'k_AB' 1389 1390 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1391 print(spin_id, spin.params) 1392 if param in spin.params: 1393 print(spin_id, spin.k_AB, spin.k_AB_err) 1394 1395 # Perform write. 1396 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1397 1398 1399 # Test the header of the value.write parameter r2. 1400 param = 'r2' 1401 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1402 1403 file = open(self.tmpdir+sep+'%s.out'%param) 1404 lines = file.readlines() 1405 file.close() 1406 1407 for i, line in enumerate(lines): 1408 # Make the string test 1409 line_split = line.split() 1410 print(line_split) 1411 1412 if len(line_split) > 1: 1413 # Break at parameter header. 1414 if line_split[0] == "#" and line_split[1] == 'mol_name': 1415 nr_split_header = len(line_split) 1416 nr_split_header_i = i 1417 break 1418 1419 # Call the line after. 1420 line_split_val = lines[nr_split_header_i + 1].split() 1421 print(line_split_val) 1422 1423 # Assert that the number of columns is equal, plus 1 for "#". 1424 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1425 1426 # Test the header of the value.write for parameter r2eff. 1427 param = 'r2eff' 1428 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1429 1430 file = open(self.tmpdir+sep+'%s.out'%param) 1431 lines = file.readlines() 1432 file.close() 1433 1434 for i, line in enumerate(lines): 1435 # Make the string test 1436 line_split = line.split() 1437 print(line_split) 1438 1439 if len(line_split) > 1: 1440 # Break at parameter header. 1441 if line_split[0] == "#" and line_split[1] == 'mol_name': 1442 nr_split_header = len(line_split) 1443 nr_split_header_i = i 1444 break 1445 1446 # Call the line after. 1447 line_split_val = lines[nr_split_header_i + 1].split() 1448 print(line_split_val) 1449 1450 # Assert that the number of columns is equal, plus 1 for "#". 1451 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1452 1453
1455 """Catch U{bug #23186<https://gna.org/bugs/?23186>}: Error calculation of individual parameter "dw" from Monte-Carlo, is based on first spin.""" 1456 1457 # Clear the data store. 1458 self.interpreter.reset() 1459 1460 # Load the state. 1461 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_23186.bz2' 1462 self.interpreter.state.load(state, force=True) 1463 1464 # Dic key to spectrometer frq. 1465 dickey = 'SQ CPMG - 599.89086220 MHz' 1466 1467 # First get the resi 0 array of sim r2a. 1468 resi_0_r2a = [] 1469 1470 # Loop over the dics in spin. 1471 for cdic in cdp.mol[0].res[0].spin[0].r2a_sim: 1472 resi_0_r2a.append(cdic[dickey]) 1473 1474 # Get stats with numpy 1475 resi_0_r2a_std = std(asarray(resi_0_r2a), ddof=1) 1476 1477 # First get the resi 86 array of sim r2a. 1478 resi_86_r2a = [] 1479 1480 # Loop over the dics in spin. 1481 for cdic in cdp.mol[0].res[1].spin[0].r2a_sim: 1482 resi_86_r2a.append(cdic[dickey]) 1483 1484 # Get stats with numpy 1485 resi_86_r2a_std = std(asarray(resi_86_r2a), ddof=1) 1486 1487 # Then get for dw. 1488 1489 # First get the array of sim dw. 1490 resi_0_dw = cdp.mol[0].res[0].spin[0].dw_sim 1491 resi_86_dw = cdp.mol[0].res[1].spin[0].dw_sim 1492 1493 # Get stats with numpy 1494 resi_0_dw_std = std(asarray(resi_0_dw), ddof=1) 1495 resi_86_dw_std = std(asarray(resi_86_dw), ddof=1) 1496 1497 # Then get for spin independent parameter. 1498 1499 # First get the array of sim dw. 1500 resi_0_kAB = cdp.mol[0].res[0].spin[0].k_AB_sim 1501 resi_86_kAB = cdp.mol[0].res[1].spin[0].k_AB_sim 1502 1503 # Get stats with numpy 1504 resi_0_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1505 resi_86_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1506 1507 # Assume they both std of k_AB values are equal 1508 self.assertEqual(resi_0_kAB_std, resi_86_kAB_std) 1509 1510 # Perform error analysis. 1511 self.interpreter.monte_carlo.error_analysis() 1512 1513 # Check values for k_AB. 1514 self.assertAlmostEqual(resi_0_kAB_std, cdp.mol[0].res[0].spin[0].k_AB_err) 1515 self.assertAlmostEqual(resi_86_kAB_std, cdp.mol[0].res[1].spin[0].k_AB_err) 1516 1517 # Check values for r2a. 1518 self.assertAlmostEqual(resi_0_r2a_std, cdp.mol[0].res[0].spin[0].r2a_err[dickey]) 1519 self.assertAlmostEqual(resi_86_r2a_std, cdp.mol[0].res[1].spin[0].r2a_err[dickey]) 1520 1521 # Check values for dw. 1522 self.assertAlmostEqual(resi_0_dw_std, cdp.mol[0].res[0].spin[0].dw_err) 1523 self.assertAlmostEqual(resi_86_dw_std, cdp.mol[0].res[1].spin[0].dw_err)
1524 1525
1527 """Catch U{bug #9999<https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations.""" 1528 1529 # Define path to data 1530 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 1531 1532 # Read data. 1533 self.interpreter.results.read(prev_data_path + sep + 'results') 1534 1535 # Now count number 1536 graph_nr = 1 1537 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1538 print("\nGraph nr %i" % graph_nr) 1539 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1540 print(exp_type, frq, offset, point, time) 1541 graph_nr += 1 1542 1543 ## Possibly do an error analysis. 1544 1545 # Check if intensity errors have already been calculated by the user. 1546 precalc = True 1547 for spin in spin_loop(skip_desel=True): 1548 # No structure. 1549 if not hasattr(spin, 'peak_intensity_err'): 1550 precalc = False 1551 break 1552 1553 # Determine if a spectrum ID is missing from the list. 1554 for id in cdp.spectrum_ids: 1555 if id not in spin.peak_intensity_err: 1556 precalc = False 1557 break 1558 1559 # Skip. 1560 if precalc: 1561 print("Skipping the error analysis as it has already been performed.") 1562 1563 else: 1564 # Loop over the spectrometer frequencies. 1565 for frq in loop_frq(): 1566 # Generate a list of spectrum IDs matching the frequency. 1567 ids = [] 1568 for id in cdp.spectrum_ids: 1569 # Check that the spectrometer frequency matches. 1570 match_frq = True 1571 if frq != None and cdp.spectrometer_frq[id] != frq: 1572 match_frq = False 1573 1574 # Add the ID. 1575 if match_frq: 1576 ids.append(id) 1577 1578 # Run the error analysis on the subset. 1579 self.interpreter.spectrum.error_analysis(subset=ids) 1580 1581 print("has_exponential_exp_type:", has_exponential_exp_type()) 1582 1583 model = 'R2eff' 1584 self.interpreter.relax_disp.select_model(model) 1585 1586 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1587 #delattr(spin, 'r2eff') 1588 #delattr(spin, 'r2eff_err') 1589 #delattr(spin, 'i0') 1590 #delattr(spin, 'i0_err') 1591 setattr(spin, 'r2eff', {}) 1592 setattr(spin, 'r2eff_err', {}) 1593 setattr(spin, 'i0', {}) 1594 setattr(spin, 'i0_err', {}) 1595 1596 # Do Grid Search 1597 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1598 1599 # Start dic. 1600 my_dic = {} 1601 1602 # Define counter for maximum elements in the numpy array list 1603 NE = 0 1604 NS = 1 1605 NM = 0 1606 NO = 0 1607 ND = 0 1608 NT = 0 1609 1610 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1611 # Save to counter. 1612 if ei > NE: 1613 NE = ei 1614 if mi > NM: 1615 NM = mi 1616 if oi > NO: 1617 NO = oi 1618 if di > ND: 1619 ND = di 1620 1621 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1622 # Save to counter. 1623 if ti > NT: 1624 NT = ti 1625 1626 # Add 1 to counter, since index start from 0. 1627 NE = NE + 1 1628 NM = NM + 1 1629 NO = NO + 1 1630 ND = ND + 1 1631 NT = NT + 1 1632 1633 # Make data array. 1634 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1635 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1636 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1637 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1638 param_key_list = [] 1639 1640 1641 # Loop over each spectrometer frequency and dispersion point. 1642 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1643 # Add key to dic. 1644 my_dic[spin_id] = {} 1645 1646 # Generate spin string. 1647 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1648 1649 # Loop over the parameters. 1650 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1651 1652 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1653 # Generate the param_key. 1654 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1655 1656 # Append key. 1657 param_key_list.append(param_key) 1658 1659 # Add key to dic. 1660 my_dic[spin_id][param_key] = {} 1661 1662 # Get the value. 1663 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1664 i0_value = getattr(cur_spin, 'i0')[param_key] 1665 1666 # Save to dic. 1667 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1668 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1669 1670 ## Now try do a line of best fit by least squares. 1671 # The peak intensities, errors and times. 1672 values = [] 1673 errors = [] 1674 times = [] 1675 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1676 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1677 values.append(value) 1678 1679 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1680 errors.append(error) 1681 times.append(time) 1682 1683 # Save to numpy arrays. 1684 values_arr[ei, 0, mi, oi, di, ti] = value 1685 errors_arr[ei, 0, mi, oi, di, ti] = error 1686 times_arr[ei, 0, mi, oi, di, ti] = time 1687 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1688 1689 # y= A exp(x * k) 1690 # w[i] = ln(y[i]) 1691 # int[i] = i0 * exp( - times[i] * r2eff); 1692 w = log(array(values)) 1693 x = - array(times) 1694 n = len(times) 1695 1696 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1697 a = 1./n * sum(w) - b * 1./n * sum(x) 1698 R2eff_est = b 1699 i0_est = exp(a) 1700 1701 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1702 my_dic[spin_id][param_key]['i0_est'] = i0_est 1703 1704 # Print value. 1705 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1706 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1707 1708 1709 # Do minimisation. 1710 set_func_tol = 1e-25 1711 set_max_iter = int(1e7) 1712 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1713 1714 # Loop over each spectrometer frequency and dispersion point. 1715 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1716 # Generate spin string. 1717 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1718 1719 # Loop over the parameters. 1720 print("Optimised parameters for spin: %s" % (spin_string)) 1721 1722 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1723 # Generate the param_key. 1724 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1725 1726 # Get the value. 1727 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1728 i0_value = getattr(cur_spin, 'i0')[param_key] 1729 1730 # Extract from dic. 1731 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1732 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1733 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1734 i0_est = my_dic[spin_id][param_key]['i0_est'] 1735 1736 # Print value. 1737 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1738 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1739 1740 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1741 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1742 1743 print(NE, NS, NM, NO, ND, NT) 1744 for param_key in param_key_list: 1745 print(" '%s'," % param_key) 1746 print(values_arr.shape) 1747 1748 # Save arrays to profiling. 1749 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1750 #save(data_path + "values_arr", values_arr) 1751 #save(data_path + "errors_arr", errors_arr) 1752 #save(data_path + "times_arr", times_arr) 1753 #save(data_path + "struct_arr", struct_arr) 1754 1755
1756 - def test_bug_atul_srivastava(self):
1757 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1758 shows it is exponential fitting, but only one time point is added per file. 1759 1760 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1761 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1762 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1763 1764 """ 1765 1766 # Data path. 1767 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1768 file = data_path + sep + 'bug_script.py' 1769 1770 # Run script. 1771 self.interpreter.script(file=file, dir=None) 1772 1773 # The grid search size (the number of increments per dimension). 1774 GRID_INC = 11 1775 1776 # Check-data. 1777 ################# 1778 1779 # Loop over spins, to see current setup. 1780 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1781 print(mol_name, resi, resn, spin_id) 1782 1783 # Loop over setup. 1784 for id in cdp.exp_type: 1785 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1786 1787 1788 # Manual minimisation. 1789 ################# 1790 if True: 1791 # Set the model. 1792 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1793 1794 # Check if intensity errors have already been calculated. 1795 check_intensity_errors() 1796 1797 # Calculate the R2eff values for the fixed relaxation time period data types. 1798 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1799 self.interpreter.minimise.calculate() 1800 1801 # Optimise the model. 1802 else: 1803 constraints = False 1804 min_algor = 'Newton' 1805 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC) 1806 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints) 1807 1808 # Inspect. 1809 if False: 1810 # Loop over attributes. 1811 par_attr_list = ['r2eff', 'i0'] 1812 1813 # Collect the estimation data. 1814 my_dic = {} 1815 param_key_list = [] 1816 est_keys = [] 1817 est_key = 'grid' 1818 est_keys.append(est_key) 1819 spin_id_list = [] 1820 1821 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1822 # Add key to dic. 1823 my_dic[spin_id] = {} 1824 1825 # Add key for estimate. 1826 my_dic[spin_id][est_key] = {} 1827 1828 # Add spin key to list. 1829 spin_id_list.append(spin_id) 1830 1831 # Generate spin string. 1832 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1833 1834 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1835 # Generate the param_key. 1836 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1837 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1838 1839 # Append key. 1840 param_key_list.append(param_key) 1841 1842 # Add key to dic. 1843 my_dic[spin_id][est_key][param_key] = {} 1844 1845 # Get the value. 1846 # Loop over err attributes. 1847 for par_attr in par_attr_list: 1848 if hasattr(cur_spin, par_attr): 1849 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1850 else: 1851 get_par_attr = 0.0 1852 1853 # Save to dic. 1854 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1855 1856 # Check number of values. 1857 values = [] 1858 errors = [] 1859 times = [] 1860 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1861 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1862 values.append(value) 1863 1864 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1865 errors.append(error) 1866 times.append(time) 1867 1868 # Save to dic. 1869 my_dic[spin_id][est_key][param_key]['values'] = values 1870 my_dic[spin_id][est_key][param_key]['errors'] = errors 1871 my_dic[spin_id][est_key][param_key]['times'] = times 1872 1873 # Analysis variables. 1874 ##################### 1875 1876 # The dispersion models. 1877 MODELS = ['R2eff', 'No Rex'] 1878 1879 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1880 MC_NUM = 10 1881 1882 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1883 MC_SIM_ALL_MODELS = False 1884 1885 # The results directory. 1886 RESULTS_DIR = ds.tmpdir 1887 1888 # The directory of results of an earlier analysis without clustering. 1889 PRE_RUN_DIR = None 1890 1891 # The model selection technique to use. 1892 MODSEL = 'AIC' 1893 1894 # The flag for only using numeric models in the final model selection. 1895 NUMERIC_ONLY = False 1896 1897 # The R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. 1898 INSIGNIFICANCE = 1.0 1899 1900 # Auto-analysis execution. 1901 self.assertRaises(RelaxError, relax_disp.Relax_disp, pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1902 1903
1905 """Test data, where peak intensities are negative in CPMG 1906 1907 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 1908 """ 1909 1910 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223' 1911 1912 # Create the spins 1913 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1914 1915 # Name the isotope for field strength scaling. 1916 self.interpreter.spin.isotope(isotope='15N') 1917 1918 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1919 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1920 1921 # Loop over the spectra settings. 1922 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1923 1924 # Make empty ncyclist 1925 ncyclist = [] 1926 1927 i = 0 1928 for line in ncycfile: 1929 ncyc = line.split()[0] 1930 time_T2 = float(line.split()[1]) 1931 vcpmg = line.split()[2] 1932 set_sfrq = float(line.split()[3]) 1933 rmsd_err = float(line.split()[4]) 1934 1935 # Test if spectrum is a reference 1936 if float(vcpmg) == 0.0: 1937 vcpmg = None 1938 else: 1939 vcpmg = round(float(vcpmg), 3) 1940 1941 # Add ncyc to list 1942 ncyclist.append(int(ncyc)) 1943 1944 # Set the current spectrum id 1945 current_id = "Z_A%s"%(i) 1946 1947 # Set the current experiment type. 1948 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 1949 1950 # Set the peak intensity errors, as defined as the baseplane RMSD. 1951 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 1952 1953 # Set the NMR field strength of the spectrum. 1954 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 1955 1956 # Relaxation dispersion CPMG constant time delay T (in s). 1957 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 1958 1959 # Set the relaxation dispersion CPMG frequencies. 1960 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 1961 1962 i += 1 1963 1964 # Specify the duplicated spectra. 1965 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 1966 1967 # Delete replicate spectrum 1968 #self.interpreter.spectrum.delete('Z_A15') 1969 1970 MODELS = [MODEL_R2EFF, MODEL_NOREX] 1971 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 1972 1973 results_dir = ds.tmpdir 1974 1975 # Execute 1976 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 1977 1978 # Check spin less R2eff points. 1979 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 1980 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 1981 if spin_id == ':4@N': 1982 self.assertEqual(len(cur_spin.r2eff), 14) 1983 else: 1984 self.assertEqual(len(cur_spin.r2eff), 15)
1985 1986
1987 - def test_check_missing_r1(self):
1988 """Test of the check_missing_r1() function.""" 1989 1990 # Set up some spins. 1991 self.setup_missing_r1_spins() 1992 1993 # Set variables. 1994 exp_type = 'R1rho' 1995 frq = 800.1 * 1E6 1996 1997 spectrum_id='test' 1998 1999 # Set an experiment type to the pipe. 2000 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 2001 2002 # Set a frequency to loop through. 2003 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 2004 2005 # Check R1 for DPL94. 2006 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2007 self.assertEqual(check_missing_r1_return, True) 2008 2009 # Check R1 for R2eff. 2010 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 2011 self.assertEqual(check_missing_r1_return, False) 2012 2013 # The path to the data files. 2014 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 2015 2016 # Now load some R1 data. 2017 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 2018 2019 # Check R1. 2020 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2021 self.assertEqual(check_missing_r1_return, False)
2022 2023
2025 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 2026 2027 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2028 2029 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2030 """ 2031 2032 # Reset. 2033 #self.interpreter.reset() 2034 2035 ## Set Experiments. 2036 model_create = 'B14' 2037 #model_create = 'NS CPMG 2-site expanded' 2038 model_analyse = 'NS CPMG 2-site 3D' 2039 2040 # Exp 1 2041 sfrq_1 = 599.8908617*1E6 2042 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2043 time_T2_1 = 0.06 2044 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2045 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2046 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2047 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2048 2049 sfrq_2 = 499.8908617*1E6 2050 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2051 time_T2_2 = 0.05 2052 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2053 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2054 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2055 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2056 2057 # Collect all exps 2058 exps = [exp_1, exp_2] 2059 2060 spins = [ 2061 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2062 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2063 ] 2064 2065 # Collect the data to be used. 2066 ds.data = [model_create, model_analyse, spins, exps] 2067 2068 # The tmp directory. None is the local directory. 2069 ds.tmpdir = ds.tmpdir 2070 2071 # The results directory. None is the local directory. 2072 #ds.resdir = None 2073 ds.resdir = ds.tmpdir 2074 2075 # Do r20_from_min_r2eff ?. 2076 ds.r20_from_min_r2eff = True 2077 2078 # Remove insignificant level. 2079 ds.insignificance = 0.0 2080 2081 # The grid search size (the number of increments per dimension). 2082 ds.GRID_INC = None 2083 2084 # The do clustering. 2085 ds.do_cluster = True 2086 2087 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2088 # The default value is 1e-25. 2089 ds.set_func_tol = 1e-1 2090 2091 # The maximum number of iterations. 2092 # The default value is 1e7. 2093 ds.set_max_iter = 1000 2094 2095 # The verbosity level. 2096 ds.verbosity = 1 2097 2098 # The rel_change WARNING level. 2099 ds.rel_change = 0.05 2100 2101 # The plot_curves. 2102 ds.plot_curves = False 2103 2104 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2105 ds.sherekhan_input = False 2106 2107 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2108 ds.opendx = False 2109 2110 # The set r2eff err. 2111 ds.r2eff_err = 0.1 2112 2113 # The print result info. 2114 ds.print_res = True 2115 2116 # Execute the script. 2117 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2118 2119 cur_spins = ds.data[2] 2120 # Compare results. 2121 for i in range(len(cur_spins)): 2122 res_name, res_num, spin_name, params = cur_spins[i] 2123 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2124 cur_spin = return_spin(cur_spin_id) 2125 2126 grid_params = ds.grid_results[i][3] 2127 2128 # Extract the clust results. 2129 min_params = ds.clust_results[i][3] 2130 # Now read the parameters. 2131 print("For spin: '%s'"%cur_spin_id) 2132 for mo_param in cur_spin.params: 2133 # The R2 is a dictionary, depending on spectrometer frequency. 2134 if isinstance(getattr(cur_spin, mo_param), dict): 2135 grid_r2 = grid_params[mo_param] 2136 min_r2 = min_params[mo_param] 2137 set_r2 = params[mo_param] 2138 for key, val in list(set_r2.items()): 2139 grid_r2_frq = grid_r2[key] 2140 min_r2_frq = min_r2[key] 2141 set_r2_frq = set_r2[key] 2142 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2143 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2144 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2145 if rel_change > ds.rel_change: 2146 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2147 print("###################################") 2148 2149 ## Make test on R2. 2150 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2151 else: 2152 grid_val = grid_params[mo_param] 2153 min_val = min_params[mo_param] 2154 set_val = params[mo_param] 2155 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2156 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2157 if rel_change > ds.rel_change: 2158 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2159 print("###################################") 2160 2161 ## Make test on parameters. 2162 if mo_param == 'dw': 2163 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2164 elif mo_param == 'kex': 2165 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2166 elif mo_param == 'pA': 2167 self.assertAlmostEqual(set_val, min_val, 2)
2168 2169
2171 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2172 2173 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2174 2175 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2176 """ 2177 2178 # Reset. 2179 #self.interpreter.reset() 2180 2181 ## Set Experiments. 2182 model_create = 'B14' 2183 #model_create = 'NS CPMG 2-site expanded' 2184 model_analyse = 'NS CPMG 2-site star' 2185 2186 # Exp 1 2187 sfrq_1 = 599.8908617*1E6 2188 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2189 time_T2_1 = 0.06 2190 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2191 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2192 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2193 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2194 2195 sfrq_2 = 499.8908617*1E6 2196 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2197 time_T2_2 = 0.05 2198 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2199 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2200 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2201 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2202 2203 # Collect all exps 2204 exps = [exp_1, exp_2] 2205 2206 spins = [ 2207 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2208 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2209 ] 2210 2211 # Collect the data to be used. 2212 ds.data = [model_create, model_analyse, spins, exps] 2213 2214 # The tmp directory. None is the local directory. 2215 ds.tmpdir = ds.tmpdir 2216 2217 # The results directory. None is the local directory. 2218 #ds.resdir = None 2219 ds.resdir = ds.tmpdir 2220 2221 # Do r20_from_min_r2eff ?. 2222 ds.r20_from_min_r2eff = True 2223 2224 # Remove insignificant level. 2225 ds.insignificance = 0.0 2226 2227 # The grid search size (the number of increments per dimension). 2228 ds.GRID_INC = None 2229 2230 # The do clustering. 2231 ds.do_cluster = True 2232 2233 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2234 # The default value is 1e-25. 2235 ds.set_func_tol = 1e-1 2236 2237 # The maximum number of iterations. 2238 # The default value is 1e7. 2239 ds.set_max_iter = 1000 2240 2241 # The verbosity level. 2242 ds.verbosity = 1 2243 2244 # The rel_change WARNING level. 2245 ds.rel_change = 0.05 2246 2247 # The plot_curves. 2248 ds.plot_curves = False 2249 2250 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2251 ds.sherekhan_input = False 2252 2253 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2254 ds.opendx = False 2255 2256 # The set r2eff err. 2257 ds.r2eff_err = 0.1 2258 2259 # The print result info. 2260 ds.print_res = True 2261 2262 # Execute the script. 2263 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2264 2265 cur_spins = ds.data[2] 2266 # Compare results. 2267 for i in range(len(cur_spins)): 2268 res_name, res_num, spin_name, params = cur_spins[i] 2269 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2270 cur_spin = return_spin(cur_spin_id) 2271 2272 grid_params = ds.grid_results[i][3] 2273 2274 # Extract the clust results. 2275 min_params = ds.clust_results[i][3] 2276 # Now read the parameters. 2277 print("For spin: '%s'"%cur_spin_id) 2278 for mo_param in cur_spin.params: 2279 # The R2 is a dictionary, depending on spectrometer frequency. 2280 if isinstance(getattr(cur_spin, mo_param), dict): 2281 grid_r2 = grid_params[mo_param] 2282 min_r2 = min_params[mo_param] 2283 set_r2 = params[mo_param] 2284 for key, val in list(set_r2.items()): 2285 grid_r2_frq = grid_r2[key] 2286 min_r2_frq = min_r2[key] 2287 set_r2_frq = set_r2[key] 2288 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2289 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2290 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2291 if rel_change > ds.rel_change: 2292 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2293 print("###################################") 2294 2295 ## Make test on R2. 2296 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2297 else: 2298 grid_val = grid_params[mo_param] 2299 min_val = min_params[mo_param] 2300 set_val = params[mo_param] 2301 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2302 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2303 if rel_change > ds.rel_change: 2304 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2305 print("###################################") 2306 2307 ## Make test on parameters. 2308 if mo_param == 'dw': 2309 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2310 elif mo_param == 'kex': 2311 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2312 elif mo_param == 'pA': 2313 self.assertAlmostEqual(set_val, min_val, 2)
2314 2315
2317 """Test synthetic cpmg data. 2318 2319 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2320 """ 2321 2322 # Reset. 2323 #self.interpreter.reset() 2324 2325 ## Set Experiments. 2326 model_create = 'NS CPMG 2-site 3D' 2327 #model_create = 'NS CPMG 2-site expanded' 2328 model_analyse = 'CR72' 2329 # Exp 1 2330 sfrq_1 = 599.8908617*1E6 2331 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2332 time_T2_1 = 0.06 2333 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2334 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2335 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2336 2337 sfrq_2 = 499.8908617*1E6 2338 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2339 time_T2_2 = 0.05 2340 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2341 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2342 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2343 2344 # Collect all exps 2345 exps = [exp_1, exp_2] 2346 2347 spins = [ 2348 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2349 ] 2350 2351 # Collect the data to be used. 2352 ds.data = [model_create, model_analyse, spins, exps] 2353 2354 # The tmp directory. None is the local directory. 2355 ds.tmpdir = ds.tmpdir 2356 2357 # The results directory. None is the local directory. 2358 #ds.resdir = None 2359 ds.resdir = ds.tmpdir 2360 2361 # Do r20_from_min_r2eff ?. 2362 ds.r20_from_min_r2eff = True 2363 2364 # Remove insignificant level. 2365 ds.insignificance = 0.0 2366 2367 # The grid search size (the number of increments per dimension). 2368 ds.GRID_INC = 8 2369 2370 # The do clustering. 2371 ds.do_cluster = False 2372 2373 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2374 # The default value is 1e-25. 2375 ds.set_func_tol = 1e-9 2376 2377 # The maximum number of iterations. 2378 # The default value is 1e7. 2379 ds.set_max_iter = 1000 2380 2381 # The verbosity level. 2382 ds.verbosity = 1 2383 2384 # The rel_change WARNING level. 2385 ds.rel_change = 0.05 2386 2387 # The plot_curves. 2388 ds.plot_curves = False 2389 2390 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2391 ds.sherekhan_input = False 2392 2393 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2394 ds.opendx = False 2395 2396 # The set r2eff err. 2397 ds.r2eff_err = 0.1 2398 2399 # The print result info. 2400 ds.print_res = False 2401 2402 # Execute the script. 2403 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2404 2405 cur_spins = ds.data[2] 2406 # Compare results. 2407 for i in range(len(cur_spins)): 2408 res_name, res_num, spin_name, params = cur_spins[i] 2409 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2410 cur_spin = return_spin(cur_spin_id) 2411 2412 grid_params = ds.grid_results[i][3] 2413 min_params = ds.min_results[i][3] 2414 # Now read the parameters. 2415 print("For spin: '%s'"%cur_spin_id) 2416 for mo_param in cur_spin.params: 2417 # The R2 is a dictionary, depending on spectrometer frequency. 2418 if isinstance(getattr(cur_spin, mo_param), dict): 2419 grid_r2 = grid_params[mo_param] 2420 min_r2 = min_params[mo_param] 2421 set_r2 = params[mo_param] 2422 for key, val in list(set_r2.items()): 2423 grid_r2_frq = grid_r2[key] 2424 min_r2_frq = min_r2[key] 2425 set_r2_frq = set_r2[key] 2426 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2427 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2428 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2429 if rel_change > ds.rel_change: 2430 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2431 print("###################################") 2432 2433 ## Make test on R2. 2434 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2435 else: 2436 grid_val = grid_params[mo_param] 2437 min_val = min_params[mo_param] 2438 set_val = params[mo_param] 2439 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2440 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2441 if rel_change > ds.rel_change: 2442 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2443 print("###################################") 2444 2445 ## Make test on parameters. 2446 if mo_param == 'dw': 2447 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2448 elif mo_param == 'kex': 2449 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2450 elif mo_param == 'pA': 2451 self.assertAlmostEqual(set_val, min_val, 3)
2452 2453
2455 """Test synthetic cpmg data. 2456 2457 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2458 Try to catch bug #22021 U{https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data. 2459 """ 2460 2461 # Reset. 2462 #self.interpreter.reset() 2463 2464 ## Set Experiments. 2465 model_create = 'NS CPMG 2-site 3D' 2466 #model_create = 'NS CPMG 2-site expanded' 2467 model_analyse = 'B14' 2468 # Exp 1 2469 sfrq_1 = 599.8908617*1E6 2470 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2471 time_T2_1 = 0.06 2472 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2473 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2474 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2475 2476 sfrq_2 = 499.8908617*1E6 2477 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2478 time_T2_2 = 0.05 2479 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2480 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2481 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2482 2483 # Collect all exps 2484 exps = [exp_1, exp_2] 2485 2486 spins = [ 2487 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2488 ] 2489 2490 # Collect the data to be used. 2491 ds.data = [model_create, model_analyse, spins, exps] 2492 2493 # The tmp directory. None is the local directory. 2494 ds.tmpdir = ds.tmpdir 2495 2496 # The results directory. None is the local directory. 2497 #ds.resdir = None 2498 ds.resdir = ds.tmpdir 2499 2500 # Do r20_from_min_r2eff ?. 2501 ds.r20_from_min_r2eff = True 2502 2503 # Remove insignificant level. 2504 ds.insignificance = 0.0 2505 2506 # The grid search size (the number of increments per dimension). 2507 ds.GRID_INC = 8 2508 2509 # The do clustering. 2510 ds.do_cluster = False 2511 2512 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2513 # The default value is 1e-25. 2514 ds.set_func_tol = 1e-9 2515 2516 # The maximum number of iterations. 2517 # The default value is 1e7. 2518 ds.set_max_iter = 1000 2519 2520 # The verbosity level. 2521 ds.verbosity = 1 2522 2523 # The rel_change WARNING level. 2524 ds.rel_change = 0.05 2525 2526 # The plot_curves. 2527 ds.plot_curves = False 2528 2529 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2530 ds.sherekhan_input = False 2531 2532 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2533 ds.opendx = False 2534 2535 # The set r2eff err. 2536 ds.r2eff_err = 0.1 2537 2538 # The print result info. 2539 ds.print_res = False 2540 2541 # Execute the script. 2542 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2543 2544 cur_spins = ds.data[2] 2545 # Compare results. 2546 for i in range(len(cur_spins)): 2547 res_name, res_num, spin_name, params = cur_spins[i] 2548 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2549 cur_spin = return_spin(cur_spin_id) 2550 2551 grid_params = ds.grid_results[i][3] 2552 min_params = ds.min_results[i][3] 2553 # Now read the parameters. 2554 print("For spin: '%s'"%cur_spin_id) 2555 for mo_param in cur_spin.params: 2556 # The R2 is a dictionary, depending on spectrometer frequency. 2557 if isinstance(getattr(cur_spin, mo_param), dict): 2558 grid_r2 = grid_params[mo_param] 2559 min_r2 = min_params[mo_param] 2560 set_r2 = params[mo_param] 2561 for key, val in list(set_r2.items()): 2562 grid_r2_frq = grid_r2[key] 2563 min_r2_frq = min_r2[key] 2564 set_r2_frq = set_r2[key] 2565 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2566 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2567 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2568 if rel_change > ds.rel_change: 2569 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2570 print("###################################") 2571 2572 ## Make test on R2. 2573 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2574 else: 2575 grid_val = grid_params[mo_param] 2576 min_val = min_params[mo_param] 2577 set_val = params[mo_param] 2578 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2579 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2580 if rel_change > ds.rel_change: 2581 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2582 print("###################################") 2583 2584 ## Make test on parameters. 2585 if mo_param == 'dw': 2586 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2587 elif mo_param == 'kex': 2588 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2589 elif mo_param == 'pA': 2590 self.assertAlmostEqual(set_val, min_val, 6)
2591 2592
2594 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2595 2596 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2597 """ 2598 2599 # Reset. 2600 #self.interpreter.reset() 2601 2602 ## Set Experiments. 2603 model_create = 'NS CPMG 2-site 3D' 2604 #model_create = 'NS CPMG 2-site expanded' 2605 model_analyse = 'CR72' 2606 2607 # Exp 1 2608 sfrq_1 = 599.8908617*1E6 2609 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2610 time_T2_1 = 0.06 2611 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2612 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2613 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2614 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2615 2616 sfrq_2 = 499.8908617*1E6 2617 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2618 time_T2_2 = 0.05 2619 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2620 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2621 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2622 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2623 2624 # Collect all exps 2625 exps = [exp_1, exp_2] 2626 2627 spins = [ 2628 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ], 2629 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ] 2630 ] 2631 2632 # Collect the data to be used. 2633 ds.data = [model_create, model_analyse, spins, exps] 2634 2635 # The tmp directory. None is the local directory. 2636 ds.tmpdir = ds.tmpdir 2637 2638 # The results directory. None is the local directory. 2639 #ds.resdir = None 2640 ds.resdir = ds.tmpdir 2641 2642 # Do r20_from_min_r2eff ?. 2643 ds.r20_from_min_r2eff = True 2644 2645 # Remove insignificant level. 2646 ds.insignificance = 0.0 2647 2648 # The grid search size (the number of increments per dimension). 2649 ds.GRID_INC = 13 2650 2651 # The do clustering. 2652 ds.do_cluster = True 2653 2654 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2655 # The default value is 1e-25. 2656 ds.set_func_tol = 1e-8 2657 2658 # The maximum number of iterations. 2659 # The default value is 1e7. 2660 ds.set_max_iter = 10000 2661 2662 # The verbosity level. 2663 ds.verbosity = 1 2664 2665 # The rel_change WARNING level. 2666 ds.rel_change = 0.05 2667 2668 # The plot_curves. 2669 ds.plot_curves = False 2670 2671 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2672 ds.sherekhan_input = False 2673 2674 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2675 ds.opendx = False 2676 2677 # The set r2eff err. 2678 ds.r2eff_err = 0.1 2679 2680 # The print result info. 2681 ds.print_res = False 2682 2683 # Execute the script. 2684 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2685 2686 cur_spins = ds.data[2] 2687 # Compare results. 2688 for i in range(len(cur_spins)): 2689 res_name, res_num, spin_name, params = cur_spins[i] 2690 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2691 cur_spin = return_spin(cur_spin_id) 2692 2693 grid_params = ds.grid_results[i][3] 2694 2695 # Extract the clust results. 2696 min_params = ds.clust_results[i][3] 2697 # Now read the parameters. 2698 print("For spin: '%s'"%cur_spin_id) 2699 for mo_param in cur_spin.params: 2700 # The R2 is a dictionary, depending on spectrometer frequency. 2701 if isinstance(getattr(cur_spin, mo_param), dict): 2702 grid_r2 = grid_params[mo_param] 2703 min_r2 = min_params[mo_param] 2704 set_r2 = params[mo_param] 2705 for key, val in list(set_r2.items()): 2706 grid_r2_frq = grid_r2[key] 2707 min_r2_frq = min_r2[key] 2708 set_r2_frq = set_r2[key] 2709 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2710 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2711 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2712 if rel_change > ds.rel_change: 2713 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2714 print("###################################") 2715 2716 ## Make test on R2. 2717 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2718 else: 2719 grid_val = grid_params[mo_param] 2720 min_val = min_params[mo_param] 2721 set_val = params[mo_param] 2722 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2723 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2724 if rel_change > ds.rel_change: 2725 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2726 print("###################################") 2727 2728 ## Make test on parameters. 2729 if mo_param == 'dw': 2730 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2731 elif mo_param == 'kex': 2732 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2733 elif mo_param == 'pA': 2734 self.assertAlmostEqual(set_val, min_val, 2)
2735 2736
2738 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2739 2740 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2741 """ 2742 2743 # Reset. 2744 #self.interpreter.reset() 2745 2746 ## Set Experiments. 2747 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2748 model_analyse = 'CR72' 2749 # Exp 1 2750 sfrq_1 = 599.8908617*1E6 2751 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2752 time_T2_1 = 0.06 2753 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2754 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2755 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2756 2757 sfrq_2 = 499.8908617*1E6 2758 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2759 time_T2_2 = 0.05 2760 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2761 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2762 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2763 2764 # Collect all exps 2765 exps = [exp_1, exp_2] 2766 2767 spins = [ 2768 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ] 2769 ] 2770 2771 # Collect the data to be used. 2772 ds.data = [model_create, model_analyse, spins, exps] 2773 2774 # The tmp directory. None is the local directory. 2775 ds.tmpdir = ds.tmpdir 2776 2777 # The results directory. None is the local directory. 2778 #ds.resdir = None 2779 ds.resdir = ds.tmpdir 2780 2781 # Do r20_from_min_r2eff ?. 2782 ds.r20_from_min_r2eff = True 2783 2784 # Remove insignificant level. 2785 ds.insignificance = 0.0 2786 2787 # The grid search size (the number of increments per dimension). 2788 ds.GRID_INC = None 2789 2790 # The do clustering. 2791 ds.do_cluster = False 2792 2793 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2794 # The default value is 1e-25. 2795 ds.set_func_tol = 1e-9 2796 2797 # The maximum number of iterations. 2798 # The default value is 1e7. 2799 ds.set_max_iter = 1000 2800 2801 # The verbosity level. 2802 ds.verbosity = 1 2803 2804 # The rel_change WARNING level. 2805 ds.rel_change = 0.05 2806 2807 # The plot_curves. 2808 ds.plot_curves = False 2809 2810 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2811 ds.sherekhan_input = False 2812 2813 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2814 ds.opendx = False 2815 2816 # The set r2eff err. 2817 ds.r2eff_err = 0.1 2818 2819 # The print result info. 2820 ds.print_res = False 2821 2822 # Execute the script. 2823 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2824 2825 # Get the spins. 2826 cur_spins = ds.data[2] 2827 2828 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2829 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2830 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2831 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2832 2833 # Copy R2eff, but not the original parameters 2834 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2835 2836 # Then select model. 2837 self.interpreter.relax_disp.select_model(model=model_analyse) 2838 2839 # Define dx.map settings. 2840 ds.dx_inc = 4 2841 ds.dx_params = ['dw', 'pA', 'kex'] 2842 2843 res_name, res_num, spin_name, params = cur_spins[0] 2844 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2845 cur_spin = return_spin(cur_spin_id) 2846 2847 print("Params for dx map is") 2848 print(ds.dx_params) 2849 print("Point param for dx map is") 2850 print(ds.dx_set_val) 2851 cur_model = model_analyse.replace(' ', '_') 2852 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2853 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2854 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point, create_par_file=True) 2855 2856 ## Check for file creation 2857 # Set filepaths. 2858 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2859 map_net = ds.tmpdir+sep+file_name_map+".net" 2860 map_general = ds.tmpdir+sep+file_name_map+".general" 2861 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir) 2862 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir) 2863 2864 point_general = ds.tmpdir+sep+file_name_point+".general" 2865 point_point = ds.tmpdir+sep+file_name_point 2866 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir) 2867 2868 # Test the files exists. 2869 self.assert_(access(map_cfg, F_OK)) 2870 self.assert_(access(map_net, F_OK)) 2871 self.assert_(access(map_general, F_OK)) 2872 self.assert_(access(map_par, F_OK)) 2873 self.assert_(access(map_plot, F_OK)) 2874 self.assert_(access(point_general, F_OK)) 2875 self.assert_(access(point_point, F_OK)) 2876 self.assert_(access(point_par, F_OK)) 2877 2878 # Open the files for testing. 2879 # Check the cfg file. 2880 print("\nChecking the dx map .cfg file.") 2881 res_file = [ 2882 '//'+"\n", 2883 '//'+"\n", 2884 '// time: Thu May 8 18:55:31 2014'+"\n", 2885 '//'+"\n", 2886 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2887 '//'+"\n", 2888 '//'+"\n", 2889 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2890 '// title: value = Control Panel'+"\n", 2891 '//'+"\n", 2892 '// workspace: width = 251, height = 142'+"\n", 2893 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2894 '//'+"\n", 2895 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2896 '// selections: maximum = 2, current = 0 '+"\n", 2897 '// option[0]: name = "Colour", value = 1'+"\n", 2898 '// option[1]: name = "Grey", value = 2'+"\n", 2899 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2900 '// label: value = Colour Selector'+"\n", 2901 '//'+"\n", 2902 '// node Image[3]:'+"\n", 2903 '// title: value = Surface'+"\n", 2904 '// depth: value = 24'+"\n", 2905 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2906 ] 2907 file = open(map_cfg, 'r') 2908 lines = file.readlines() 2909 file.close() 2910 for i in range(len(res_file)): 2911 # Skip time point 2912 if i == 2: 2913 continue 2914 self.assertEqual(res_file[i], lines[i]) 2915 2916 print("\nChecking the dx map .general file.") 2917 res_file = [ 2918 'file = CR72_map_1_N'+"\n", 2919 'grid = 5 x 5 x 5'+"\n", 2920 'format = ascii'+"\n", 2921 'interleaving = field'+"\n", 2922 'majority = row'+"\n", 2923 'field = data'+"\n", 2924 'structure = scalar'+"\n", 2925 'type = float'+"\n", 2926 'dependency = positions'+"\n", 2927 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2928 ''+"\n", 2929 'end'+"\n", 2930 ] 2931 file = open(map_general, 'r') 2932 lines = file.readlines() 2933 file.close() 2934 for i in range(len(res_file)): 2935 # Skip time point 2936 #if i == 2: 2937 # continue 2938 self.assertEqual(res_file[i], lines[i]) 2939 2940 print("\nChecking the dx point .general file.") 2941 res_file = [ 2942 'file = CR72_point_1_N'+"\n", 2943 'points = 2'+"\n", 2944 'format = ascii'+"\n", 2945 'interleaving = field'+"\n", 2946 'field = locations, field0'+"\n", 2947 'structure = 3-vector, scalar'+"\n", 2948 'type = float, float'+"\n", 2949 ''+"\n", 2950 'end'+"\n", 2951 ] 2952 file = open(point_general, 'r') 2953 lines = file.readlines() 2954 file.close() 2955 for i in range(len(res_file)): 2956 # Skip time point 2957 #if i == 2: 2958 # continue 2959 self.assertEqual(res_file[i], lines[i]) 2960 2961 print("\nChecking the dx point point file.") 2962 res_file = [ 2963 '0.8 3.92 0.39964 1'+"\n", 2964 '0.76981 3.9169 0.41353 1'+"\n", 2965 ] 2966 file = open(point_point, 'r') 2967 lines = file.readlines() 2968 file.close() 2969 for i in range(len(res_file)): 2970 # Skip time point 2971 #if i == 2: 2972 # continue 2973 self.assertEqual(res_file[i], lines[i]) 2974 2975 print("\nChecking the dx point par file.") 2976 res_file = [ 2977 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 2978 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 2979 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n", 2980 ] 2981 res_file2 = [ 2982 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 2983 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 2984 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n", 2985 ] # Python 2.5 and 3.1. 2986 file = open(point_par, 'r') 2987 lines = file.readlines() 2988 file.close() 2989 for i in range(len(res_file)): 2990 if lines[i] != res_file[i] and lines[i] != res_file2[i]: 2991 self.assertEqual(res_file[i], lines[i]) 2992 2993 print("\nChecking the matplotlib surface plot file.") 2994 res_file = [ 2995 'from copy import deepcopy'+"\n", 2996 'import numpy as np'+"\n", 2997 'import scipy.interpolate'+"\n", 2998 'from numpy.ma import masked_where'+"\n", 2999 ''+"\n", 3000 'from mpl_toolkits.mplot3d import axes3d'+"\n", 3001 'import matplotlib.pyplot as plt'+"\n", 3002 'from matplotlib import cm'+"\n", 3003 ''+"\n", 3004 '# Open file and get header.'+"\n", 3005 'mapfile_name = "%s.par"'%file_name_map+"\n", 3006 'pointfile_name = "%s.par"'%file_name_point+"\n", 3007 ''+"\n", 3008 ] 3009 file = open(map_plot, 'r') 3010 lines = file.readlines() 3011 file.close() 3012 for i in range(len(res_file)): 3013 self.assertEqual(res_file[i], lines[i])
3014 3015
3017 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 3018 3019 # Reset. 3020 self.interpreter.reset() 3021 3022 # Load the base data. 3023 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 3024 self.interpreter.state.load(data_path+sep+'r2eff_values') 3025 3026 # The type. 3027 curve_type = get_curve_type(id='500_133.33.in') 3028 self.assertEqual(curve_type, 'fixed time')
3029 3030
3031 - def test_curve_type_r1rho_exponential(self, model=None):
3032 """Test the curve type detection using the 'M61' exponential test data.""" 3033 3034 # Reset. 3035 self.interpreter.reset() 3036 3037 # Load the base data. 3038 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 3039 self.interpreter.state.load(data_path+sep+'r2eff_values') 3040 3041 # The type. 3042 curve_type = get_curve_type(id='nu_2000_ncyc9') 3043 self.assertEqual(curve_type, 'exponential')
3044 3045
3046 - def test_curve_type_r1rho_fixed_time(self, model=None):
3047 """Test the curve type detection using the 'TP02' fixed time test data.""" 3048 3049 # Reset. 3050 self.interpreter.reset() 3051 3052 # Load the base data. 3053 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 3054 self.interpreter.state.load(data_path+sep+'r2eff_values') 3055 3056 # The type. 3057 curve_type = get_curve_type(id='nu_1000.0_500MHz') 3058 self.assertEqual(curve_type, 'fixed time')
3059 3060
3061 - def test_dpl94_data_to_dpl94(self):
3062 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 3063 3064 # Fixed time variable. 3065 ds.fixed = True 3066 3067 # Execute the script. 3068 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py') 3069 3070 # The original parameters. 3071 i0 = [100000.0, 20000.0] 3072 r1rho_prime = [2.25, 24.0] 3073 pA = 0.7 3074 kex = 1000.0 3075 delta_omega = [1.0, 2.0] 3076 phi_ex = [] 3077 for i in range(2): 3078 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 3079 3080 # Switch to the 'DPL94' model data pipe, then check for each spin. 3081 self.interpreter.pipe.switch('DPL94 - relax_disp') 3082 spin_index = 0 3083 for spin, spin_id in spin_loop(return_id=True): 3084 # Printout. 3085 print("\nSpin %s." % spin_id) 3086 3087 # Check the fitted parameters. 3088 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 3089 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 3090 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 3091 3092 # Increment the spin index. 3093 spin_index += 1
3094 3095
3096 - def test_dx_map_clustered(self):
3097 """Test making dx_map for residues under clustered calculation. 3098 3099 This uses CPMG data from: 3100 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE 3101 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 3102 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>} 3103 """ 3104 3105 # Define path to data 3106 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 3107 3108 # Read data. 3109 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 3110 3111 # Get residue of interest. 3112 cur_spin_id = ":%i@%s"%(52, 'N') 3113 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3114 3115 # Get the spin container. 3116 cur_spin = return_spin(cur_spin_id) 3117 3118 # Get the chi2 value 3119 pre_chi2 = cur_spin.chi2 3120 3121 # Then do a local minimisation. 3122 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3123 self.interpreter.minimise.calculate() 3124 3125 # Get the chi2 value after calculation. 3126 calc_chi2 = cur_spin.chi2 3127 3128 # Assert calculation is equal. 3129 self.assertAlmostEqual(pre_chi2, calc_chi2) 3130 3131 # Define dx.map settings. 3132 dx_inc = 2 3133 dx_inc_sides = dx_inc / 2 3134 3135 dx_params = ['dw', 'pA', 'kex'] 3136 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex] 3137 3138 print("Params for dx map is") 3139 print(dx_params) 3140 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3141 print(dx_point_clustered_min) 3142 3143 # Define file_names. 3144 cur_model = 'CR72' 3145 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3146 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3147 3148 # Step-size of parameter is 10 % 3149 param_delta = 0.1 3150 3151 # Determine bounds for lower and upper 3152 lower = [] 3153 upper = [] 3154 for i, param_val in enumerate(dx_point_clustered_min): 3155 param = dx_params[i] 3156 step_val = param_delta * param_val 3157 step_length = step_val * dx_inc_sides 3158 3159 # Calculate value 3160 low_val = param_val - step_length 3161 lower.append(low_val) 3162 3163 upp_val = param_val + step_length 3164 upper.append(upp_val) 3165 3166 print("For param %s, lower=%3.3f, upper=%3.3f, step_value=%3.3f, steps=%i, centered at=%3.3f"% (param, low_val, upp_val, step_val, dx_inc, param_val)) 3167 3168 # If the number of increments are 2, there will be 3 point calculations per parameter. 3169 # Since we have ordered the lower and upper limits on sides of the parameter, the middle index should give us the expected global value. 3170 dx_param_indexes = dx_inc + 1 3171 dx_point_index = dx_inc_sides + 1 3172 3173 # Find the line number. 3174 line = 1 3175 for i in range(1, dx_param_indexes + 1): 3176 for j in range(1, dx_param_indexes + 1): 3177 for k in range(1, dx_param_indexes + 1): 3178 if i == dx_point_index and j == dx_point_index and k == dx_point_index: 3179 line_chi2 = line 3180 # Add to line counter. 3181 line += 1 3182 3183 # Define temporary folder. 3184 result_dir = self.tmpdir 3185 3186 # For testing. 3187 #result_dir = None 3188 #lower = None 3189 #upper = None 3190 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3191 3192 3193 # Then do the map. 3194 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point) 3195 3196 # Print where to locate values. 3197 nr_chi2_val = dx_param_indexes**3 3198 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3199 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) ) 3200 3201 ## Check for file creation 3202 # Set filepaths. 3203 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3204 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3205 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3206 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3207 3208 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3209 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3210 3211 # Test the files exists. 3212 self.assert_(access(map_cfg, F_OK)) 3213 self.assert_(access(map_net, F_OK)) 3214 self.assert_(access(map_general, F_OK)) 3215 self.assert_(access(point_general, F_OK)) 3216 self.assert_(access(point_point, F_OK)) 3217 3218 # Open the file, and assert the chi2 value is as expected. 3219 get_data = extract_data(file=map_name) 3220 3221 # Extract line 0, column 0. 3222 test = float(get_data[line_chi2-1][0]) 3223 3224 # Assert. 3225 self.assertAlmostEqual(test, pre_chi2, 6)
3226 3227
3229 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file. 3230 3231 U{Task #7860<https://gna.org/task/index.php?7860>} : When dx_map is issued, create a parameter file which maps parameters to chi2 value. 3232 3233 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 3234 """ 3235 3236 # Define path to data 3237 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting' 3238 3239 # Read data. 3240 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2') 3241 3242 # Get residue of interest. 3243 cur_spin_id = ":%i@%s"%(65, 'N') 3244 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3245 3246 # Get the spin container. 3247 cur_spin = return_spin(cur_spin_id) 3248 3249 # Get the chi2 value 3250 pre_chi2 = cur_spin.chi2 3251 3252 # Then do a local minimisation. 3253 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3254 self.interpreter.minimise.calculate() 3255 3256 # Get the chi2 value after calculation. 3257 calc_chi2 = cur_spin.chi2 3258 3259 # Assert calculation is equal. 3260 self.assertAlmostEqual(pre_chi2, calc_chi2) 3261 3262 # Define dx.map settings. 3263 dx_inc = 2 3264 dx_params = ['dw', 'k_AB', 'r2a'] 3265 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']] 3266 3267 print("Params for dx map is") 3268 print(dx_params) 3269 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3270 print(dx_point_clustered_min) 3271 3272 # Define file_names. 3273 cur_model = 'TSMFK01' 3274 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3275 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3276 3277 # Determine bounds for lower and upper 3278 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]] 3279 upper = [19.0, 2.4, 9.5] 3280 3281 # Define temporary folder. 3282 result_dir = self.tmpdir 3283 3284 # For testing. 3285 #result_dir = None 3286 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3287 3288 # Then do the map. 3289 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point, create_par_file=True) 3290 3291 # Print where to locate values. 3292 nr_chi2_val = (dx_inc + 1)**3 3293 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3294 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) ) 3295 3296 ## Check for file creation 3297 # Set filepaths. 3298 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3299 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3300 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3301 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3302 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir) 3303 3304 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3305 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3306 3307 # Test the files exists. 3308 self.assert_(access(map_cfg, F_OK)) 3309 self.assert_(access(map_net, F_OK)) 3310 self.assert_(access(map_general, F_OK)) 3311 self.assert_(access(map_par, F_OK)) 3312 self.assert_(access(point_general, F_OK)) 3313 self.assert_(access(point_point, F_OK)) 3314 3315 print("\nParams for dx map is") 3316 print(dx_params) 3317 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3318 print(dx_point_clustered_min, "\n") 3319 3320 # Open the parameter chi2 file, and assert the chi2 value in the sorted parameter file is not lower that than the global minimisation. 3321 get_data = extract_data(file=map_par) 3322 3323 # Extract line 1, column 9. 3324 test = float(get_data[1][9]) 3325 3326 # Print data if map contain a lower value than the global minimised value. 3327 if test < pre_chi2: 3328 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test)) 3329 for line in get_data: 3330 print(line)
3331 3332 # Assert that the initial global chi2 is lower than the map value. 3333 3334 # The following test was taken out, since this a particular interesting case. 3335 # There exist a double minimum, where relax has not found the global minimum. 3336 # This is due to not grid searching for R2A, but using the minimum 3337 #self.assert_(pre_chi2 < test) 3338 3339
3340 - def test_estimate_r2eff_err(self):
3341 """Test the user function for estimating R2eff errors from exponential curve fitting. 3342 3343 This follows Task 7822. 3344 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3345 3346 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3347 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3348 """ 3349 3350 # Cluster residues 3351 cluster_ids = [ 3352 ":13@N", 3353 ":15@N", 3354 ":16@N", 3355 ":25@N", 3356 ":26@N", 3357 ":28@N", 3358 ":39@N", 3359 ":40@N", 3360 ":41@N", 3361 ":43@N", 3362 ":44@N", 3363 ":45@N", 3364 ":49@N", 3365 ":52@N", 3366 ":53@N"] 3367 3368 # Load the data. 3369 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3370 3371 # The dispersion models. 3372 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3373 3374 # The grid search size (the number of increments per dimension). 3375 GRID_INC = None 3376 3377 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3378 MC_NUM = 3 3379 3380 # Model selection technique. 3381 MODSEL = 'AIC' 3382 3383 # Execute the auto-analysis (fast). 3384 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3385 OPT_FUNC_TOL = 1e-25 3386 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3387 OPT_MAX_ITERATIONS = 10000000 3388 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3389 3390 result_dir_name = ds.tmpdir 3391 3392 # Make all spins free 3393 for curspin in cluster_ids: 3394 self.interpreter.relax_disp.cluster('free spins', curspin) 3395 # Shut them down 3396 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 3397 3398 # Select only a subset of spins for global fitting 3399 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3400 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3401 3402 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3403 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3404 3405 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3406 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3407 3408 # Set the model. 3409 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3410 3411 # Check if intensity errors have already been calculated. 3412 check_intensity_errors() 3413 3414 # Do a grid search. 3415 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 3416 3417 # Minimise. 3418 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 3419 3420 # Estimate R2eff errors. 3421 self.interpreter.relax_disp.r2eff_err_estimate() 3422 3423 r1_fit = True 3424 3425 # Run the analysis. 3426 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3427 3428 # Verify the data. 3429 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3430 3431
3433 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3434 3435 This follows Task 7822. 3436 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3437 3438 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3439 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3440 """ 3441 3442 # Cluster residues 3443 cluster_ids = [ 3444 ":13@N", 3445 ":15@N", 3446 ":16@N", 3447 ":25@N", 3448 ":26@N", 3449 ":28@N", 3450 ":39@N", 3451 ":40@N", 3452 ":41@N", 3453 ":43@N", 3454 ":44@N", 3455 ":45@N", 3456 ":49@N", 3457 ":52@N", 3458 ":53@N"] 3459 3460 # Load the data. 3461 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3462 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3463 3464 # Set pipe name, bundle and type. 3465 pipe_name = 'base pipe' 3466 pipe_bundle = 'relax_disp' 3467 pipe_type = 'relax_disp' 3468 3469 # Create the data pipe. 3470 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3471 3472 file = data_path + '1_setup_r1rho_GUI.py' 3473 self.interpreter.script(file=file, dir=None) 3474 3475 # The dispersion models. 3476 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3477 3478 # The grid search size (the number of increments per dimension). 3479 GRID_INC = None 3480 3481 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3482 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3483 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3484 EXP_MC_NUM = -1 3485 3486 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3487 MC_NUM = 3 3488 3489 # Model selection technique. 3490 MODSEL = 'AIC' 3491 3492 # Execute the auto-analysis (fast). 3493 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3494 OPT_FUNC_TOL = 1e-25 3495 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3496 OPT_MAX_ITERATIONS = 10000000 3497 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3498 3499 # Make all spins free 3500 #for curspin in cluster_ids: 3501 # self.interpreter.relax_disp.cluster('free spins', curspin) 3502 # # Shut them down 3503 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3504 3505 # Make all spins free 3506 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3507 3508 # Select only a subset of spins for global fitting 3509 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3510 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3511 3512 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3513 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3514 3515 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3516 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3517 3518 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3519 print(spin_id) 3520 3521 result_dir_name = self.tmpdir 3522 r1_fit = True 3523 3524 # Run the analysis. 3525 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3526 3527 # Verify the data. 3528 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3529 3530
3532 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3533 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3534 3535 This follows Task 7822. 3536 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3537 3538 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3539 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3540 3541 NOTE: The difference in the methods was due to a bug in relax! 3542 U{bug #22554<https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected. 3543 3544 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3545 """ 3546 3547 # Define data path. 3548 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 3549 3550 # Create pipe. 3551 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3552 3553 # Read results for 2000 MC simulations. 3554 self.interpreter.results.read(prev_data_path + sep + 'results') 3555 3556 # Start dic. 3557 my_dic = {} 3558 param_key_list = [] 3559 3560 # Do boot strapping ? 3561 do_boot = True 3562 if do_boot: 3563 min_algor = 'Newton' 3564 min_options = () 3565 sim_boot = 200 3566 scaling_list = [1.0, 1.0] 3567 3568 # First check sim values. 3569 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3570 # Add key to dic. 3571 my_dic[spin_id] = {} 3572 3573 # Loop over sim. 3574 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3575 # Loop over all exp type. 3576 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3577 # Generate the param_key. 3578 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3579 r2eff_sim_point = r2eff_sim[param_key] 3580 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3581 3582 # Assert point are higher than 0.0. 3583 #point_info = "r2eff=%3.2f i0=%3.2f, at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, at sim index %i." % (r2eff_sim_point, i0_sim_point, frq/1E6, offset, point, i) 3584 #print(point_info) 3585 self.assert_(r2eff_sim_point > 0.0) 3586 self.assert_(i0_sim_point > 0.0) 3587 3588 # Get the data. 3589 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3590 # Generate spin string. 3591 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3592 3593 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3594 # Generate the param_key. 3595 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3596 3597 # Loop over all sim, and collect data. 3598 r2eff_sim_l = [] 3599 i0_sim_l = [] 3600 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3601 i0_sim = cur_spin.i0_sim[i] 3602 3603 r2eff_sim_i = r2eff_sim[param_key] 3604 r2eff_sim_l.append(r2eff_sim_i) 3605 i0_sim_i = i0_sim[param_key] 3606 i0_sim_l.append(i0_sim_i) 3607 3608 # Take the standard deviation of all values. 3609 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3610 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3611 3612 # Append key. 3613 param_key_list.append(param_key) 3614 3615 # Add key to dic. 3616 my_dic[spin_id][param_key] = {} 3617 3618 # Get the value. 3619 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3620 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3621 i0 = getattr(cur_spin, 'i0')[param_key] 3622 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3623 3624 # Save to dic. 3625 my_dic[spin_id][param_key]['r2eff'] = r2eff 3626 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3627 my_dic[spin_id][param_key]['i0'] = i0 3628 my_dic[spin_id][param_key]['i0_err'] = i0_err 3629 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3630 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3631 3632 # Assert values are equal 3633 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3634 self.assertAlmostEqual(i0_sim_err, i0_err) 3635 3636 if do_boot: 3637 values = [] 3638 errors = [] 3639 times = [] 3640 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3641 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3642 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3643 times.append(time) 3644 3645 # Convert to numpy array. 3646 values = asarray(values) 3647 errors = asarray(errors) 3648 times = asarray(times) 3649 3650 R_m_sim_l = [] 3651 I0_m_sim_l = [] 3652 for j in range(sim_boot): 3653 if j in range(0, 100000, 100): 3654 print("Simulation %i"%j) 3655 # Start minimisation. 3656 3657 # Produce errors 3658 I_err = [] 3659 for j, error in enumerate(errors): 3660 I_error = gauss(values[j], error) 3661 I_err.append(I_error) 3662 # Convert to numpy array. 3663 I_err = asarray(I_err) 3664 3665 x0 = [r2eff, i0] 3666 model = Relax_fit_opt(model='exp', num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3667 3668 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0) 3669 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3670 R_m_sim_l.append(R_m_sim_j) 3671 I0_m_sim_l.append(I0_m_sim_j) 3672 3673 # Get stats on distribution. 3674 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3675 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3676 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3677 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3678 3679 3680 # A new data pipe. 3681 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3682 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3683 3684 # Delete old errors. 3685 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3686 delattr(cur_spin, 'r2eff_err') 3687 delattr(cur_spin, 'i0_err') 3688 3689 # Set the model. 3690 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3691 3692 # Estimate R2eff and errors. 3693 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3694 3695 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3696 # Generate spin string. 3697 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3698 3699 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3700 # Generate the param_key. 3701 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3702 3703 # Get the value. 3704 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3705 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3706 i0_est = getattr(cur_spin, 'i0')[param_key] 3707 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3708 3709 # Get from dic. 3710 r2eff = my_dic[spin_id][param_key]['r2eff'] 3711 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3712 i0 = my_dic[spin_id][param_key]['i0'] 3713 i0_err = my_dic[spin_id][param_key]['i0_err'] 3714 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3715 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3716 3717 if do_boot: 3718 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3719 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3720 else: 3721 r2eff_boot_err = 0.0 3722 i0_boot_err = 0.0 3723 3724 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3725 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ), 3726 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) ) 3727 3728 3729 # Now do it manually. 3730 estimate_r2eff(method='scipy.optimize.leastsq') 3731 3732 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3733 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3734 3735 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3736 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3737 3738 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3739 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3740 3741 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3742 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3743 3744 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3745 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3746 3747 3748
3749 - def test_exp_fit(self):
3750 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3751 3752 # Execute the script. 3753 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3754 3755 # The original exponential curve parameters. 3756 res_data = [ 3757 [15., 10., 20000., 25000.], 3758 [12., 11., 50000., 51000.], 3759 [17., 9., 100000., 96000.] 3760 ] 3761 3762 # List of parameters which do not belong to the model. 3763 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3764 3765 # Checks for each residue. 3766 for i in range(len(res_data)): 3767 # Printout. 3768 print("\nResidue number %s." % (i+1)) 3769 3770 # Check the fitted parameters. 3771 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3772 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3773 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3) 3774 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3) 3775 3776 # Check the simulation errors. 3777 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3778 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3779 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3780 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3781 3782 # Check that certain parameters are not present. 3783 for param in blacklist: 3784 print("\tChecking for the absence of the '%s' parameter." % param) 3785 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3786 3787 # Check the clustering information. 3788 self.assert_(hasattr(cdp, 'clustering')) 3789 keys = ['free spins', 'cluster'] 3790 for key in keys: 3791 self.assert_(key in cdp.clustering) 3792 self.assert_('test' not in cdp.clustering) 3793 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3794 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3795 3796
3797 - def test_finite_value(self):
3798 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3799 3800 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3801 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3802 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3803 3804 scaling_list = [1.0, 1.0] 3805 model = Relax_fit_opt(model='exp', num_params=2, values=I, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3806 3807 R = - 500. 3808 I0 = 1000. 3809 params = [R, I0] 3810 3811 chi2 = model.func(params) 3812 3813 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3814 self.assertNotEqual(chi2, inf)
3815 3816
3817 - def test_hansen_catia_input(self):
3818 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3819 3820 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3821 """ 3822 3823 # Load the R2eff results file. 3824 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3825 self.interpreter.results.read(file_name) 3826 self.interpreter.deselect.spin(':4') 3827 3828 # The spin isotopes. 3829 self.interpreter.spin.isotope("15N") 3830 3831 # Generate the input files. 3832 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3833 3834 # Check the r2eff set files. 3835 print("\nChecking the R2eff input set files.") 3836 files = ['data_set_500.inp', 'data_set_500.inp'] 3837 for file in files: 3838 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3839 data_set_500 = [ 3840 "ID=500\n", 3841 "Sfrq = 500\n", 3842 "Temperature = 0.0\n", 3843 "Nucleus = N15\n", 3844 "Couplednucleus = H1\n", 3845 "Time_equil = 0.0\n", 3846 "Pwx_cp = 0.0\n", 3847 "Taub = 0.0\n", 3848 "Time_T2 = 0.03\n", 3849 "Xcar = 0.0\n", 3850 "Seqfil = CW_CPMG\n", 3851 "Minerror = (2.%;0.5/s)\n", 3852 "Basis = (Iph_7)\n", 3853 "Format = (0;1;2)\n", 3854 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3855 "Data = (\n", 3856 " [70N;spin_70_N_500.cpmg];\n", 3857 " [71N;spin_71_N_500.cpmg];\n", 3858 ")\n", 3859 ] 3860 file = open(ds.tmpdir+sep+files[0]) 3861 lines = file.readlines() 3862 file.close() 3863 for i in range(len(data_set_500)): 3864 # Skip the data directory, as this is a random file name. 3865 if i == 14: 3866 continue 3867 3868 self.assertEqual(data_set_500[i], lines[i]) 3869 3870 # Check the r2eff files. 3871 print("\nChecking the R2eff input files.") 3872 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3873 for file in files: 3874 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3875 spin_70_N_500 = [ 3876 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3877 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3878 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3879 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3880 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3881 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3882 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3883 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3884 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3885 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3886 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3887 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3888 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3889 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3890 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3891 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3892 ] 3893 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3894 lines = file.readlines() 3895 file.close() 3896 for i in range(len(lines)): 3897 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3898 for i in range(len(spin_70_N_500)): 3899 self.assertEqual(spin_70_N_500[i], lines[i]) 3900 3901 # Check the main file. 3902 print("\nChecking the main CATIA execution file.") 3903 main_file = [ 3904 "ReadDataset(data_set_500.inp)\n", 3905 "ReadDataset(data_set_800.inp)\n", 3906 "ReadParam_Global(ParamGlobal.inp)\n", 3907 "ReadParam_Local(ParamSet1.inp)\n", 3908 "\n", 3909 "FreeLocalParam(all;Omega;false)\n", 3910 "FreeLocalParam(all;R1iph_500;false)\n", 3911 "FreeLocalParam(all;R1iph_800;false)\n", 3912 "\n", 3913 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3914 "\n", 3915 "PrintParam(output/GlobalParam.fit;global)\n", 3916 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3917 "PrintData(output/)\n", 3918 "\n", 3919 "ChiSq(all;all)\n", 3920 "exit(0)\n" 3921 ] 3922 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3923 lines = file.readlines() 3924 file.close() 3925 for i in range(len(main_file)): 3926 self.assertEqual(main_file[i], lines[i])
3927 3928
3930 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3931 3932 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3933 """ 3934 3935 # Set the model. 3936 ds.models = [ 3937 MODEL_NOREX, 3938 MODEL_LM63, 3939 MODEL_CR72, 3940 MODEL_IT99 3941 ] 3942 3943 # Execute the script. 3944 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3945 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3946 3947 # The R20 keys. 3948 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3949 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3950 3951 # The 'No Rex' model checks. 3952 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3953 spin70 = return_spin(":70") 3954 spin71 = return_spin(":71") 3955 print("\n\nOptimised parameters:\n") 3956 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3957 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3958 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3959 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3960 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3961 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3962 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 3963 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3964 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3965 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 3966 3967 # The 'LM63' model checks. 3968 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 3969 spin70 = return_spin(":70") 3970 spin71 = return_spin(":71") 3971 print("\n\nOptimised parameters:\n") 3972 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3973 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3974 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3975 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 3976 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3977 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3978 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 3979 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 3980 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 3981 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 3982 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 3983 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 3984 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 3985 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 3986 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 3987 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 3988 3989 # The 'CR72' model checks. 3990 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3991 spin70 = return_spin(":70") 3992 spin71 = return_spin(":71") 3993 print("\n\nOptimised parameters:\n") 3994 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3995 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3996 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3997 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3998 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3999 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4000 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4001 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4002 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4003 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4004 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4005 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4006 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4007 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4008 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4009 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4010 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4011 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4012 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
4013 4014
4016 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 4017 4018 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4019 """ 4020 4021 # Set the model and numeric flag. 4022 ds.models = [ 4023 MODEL_NOREX, 4024 MODEL_CR72, 4025 MODEL_NS_CPMG_2SITE_EXPANDED 4026 ] 4027 ds.numeric_only = True 4028 4029 # Execute the script. 4030 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 4031 4032 # The R20 keys. 4033 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4034 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4035 4036 # The 'No Rex' model checks. 4037 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4038 spin70 = return_spin(":70") 4039 spin71 = return_spin(":71") 4040 print("\n\nOptimised parameters:\n") 4041 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4042 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4043 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4044 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4045 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4046 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4047 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 4048 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4049 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4050 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 4051 4052 # The 'CR72' model checks. 4053 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4054 spin70 = return_spin(":70") 4055 spin71 = return_spin(":71") 4056 print("\n\nOptimised parameters:\n") 4057 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4058 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4059 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4060 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4061 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4062 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4063 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4064 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4065 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4066 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4067 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4068 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4069 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4070 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4071 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4072 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4073 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4074 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4075 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 4076 4077 # The 'NS CPMG 2-site expanded' model checks. 4078 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 4079 spin70 = return_spin(":70") 4080 spin71 = return_spin(":71") 4081 print("\n\nOptimised parameters:\n") 4082 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4083 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4084 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4085 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4086 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4087 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4088 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4089 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 4090 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 4091 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 4092 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 4093 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 4094 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 4095 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 4096 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 4097 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 4098 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 4099 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 4100 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 4101 4102 # The final data pipe checks. 4103 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 4104 spin70 = return_spin(":70") 4105 spin71 = return_spin(":71") 4106 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 4107 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4108 4109
4111 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 4112 4113 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4114 """ 4115 4116 # Set the model. 4117 ds.models = [ 4118 MODEL_NOREX, 4119 MODEL_LM63, 4120 MODEL_CR72, 4121 MODEL_IT99 4122 ] 4123 4124 # Execute the script. 4125 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 4126 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 4127 4128 # The R20 keys. 4129 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4130 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4131 4132 # The 'No Rex' model checks. 4133 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4134 spin70 = return_spin(":70") 4135 spin71 = return_spin(":71") 4136 print("\n\nOptimised parameters:\n") 4137 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4138 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4139 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4140 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4141 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4142 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4143 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4144 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4145 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4146 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4147 4148 # The 'LM63' model checks. 4149 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4150 spin70 = return_spin(":70") 4151 spin71 = return_spin(":71") 4152 print("\n\nOptimised parameters:\n") 4153 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4154 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4155 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4156 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4157 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4158 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4159 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4160 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4161 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4162 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4163 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4164 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4165 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4166 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4167 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4168 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4169 4170 # The 'CR72' model checks. 4171 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4172 spin70 = return_spin(":70") 4173 spin71 = return_spin(":71") 4174 print("\n\nOptimised parameters:\n") 4175 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4176 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4177 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4178 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4179 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4180 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4181 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4182 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4183 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4184 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4185 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4186 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4187 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4188 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 4189 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 4190 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 4191 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 4192 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 4193 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4194 4195
4197 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 4198 4199 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4200 """ 4201 4202 # Set the model. 4203 ds.models = [ 4204 MODEL_R2EFF, 4205 MODEL_NOREX, 4206 MODEL_CR72, 4207 MODEL_NS_CPMG_2SITE_EXPANDED 4208 ] 4209 4210 # Execute the script. 4211 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 4212 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4213 4214 # The R20 keys. 4215 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4216 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4217 4218 # The 'No Rex' model checks. 4219 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4220 spin4 = return_spin(":4") 4221 spin70 = return_spin(":70") 4222 spin71 = return_spin(":71") 4223 print("\n\nOptimised parameters:\n") 4224 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4225 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4226 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4227 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4228 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 4229 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 4230 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 4231 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 4232 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 4233 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 4234 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 4235 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 4236 4237 # The 'CR72' model checks. 4238 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4239 spin4 = return_spin(":4") 4240 spin70 = return_spin(":70") 4241 spin71 = return_spin(":71") 4242 print("\n\nOptimised parameters:\n") 4243 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4244 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4245 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4246 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 4247 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 4248 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 4249 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4250 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 4251 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 4252 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 4253 self.assertAlmostEqual(spin4.dw, 0.0, 2) 4254 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 4255 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 4256 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 4257 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 4258 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 4259 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 4260 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 4261 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 4262 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 4263 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 4264 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2) 4265 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 4266 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4267 4268
4270 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 4271 4272 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4273 """ 4274 4275 # Base data setup. 4276 self.setup_hansen_cpmg_data(model='CR72') 4277 4278 # Alias the spins. 4279 spin70 = return_spin(":70") 4280 spin71 = return_spin(":71") 4281 4282 # The R20 keys. 4283 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4284 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4285 4286 # Set the initial parameter values. 4287 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4288 spin70.pA = 0.9 4289 spin70.dw = 6.0 4290 spin70.kex = 1500.0 4291 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 4292 spin71.pA = 0.9 4293 spin71.dw = 4.0 4294 spin71.kex = 1900.0 4295 4296 # Low precision optimisation. 4297 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4298 4299 # Printout. 4300 print("\n\nOptimised parameters:\n") 4301 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4302 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4303 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4304 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4305 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4306 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4307 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4308 4309 # Checks for residue :70. 4310 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 4311 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 4312 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 4313 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 4314 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 4315 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 4316 4317 # Checks for residue :71. 4318 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 4319 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 4320 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 4321 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 4322 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 4323 4324 # Test the conversion to k_AB from kex and pA. 4325 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4326 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4327 4328 # Test the conversion to k_BA from kex and pA. 4329 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4330 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4331 4332
4334 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 4335 4336 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4337 """ 4338 4339 # Base data setup. 4340 self.setup_hansen_cpmg_data(model='CR72 full') 4341 4342 # Alias the spins. 4343 spin70 = return_spin(":70") 4344 spin71 = return_spin(":71") 4345 4346 # The R20 keys. 4347 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4348 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4349 4350 # Set the initial parameter values. 4351 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 4352 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 4353 spin70.pA = 0.9 4354 spin70.dw = 6.0 4355 spin70.kex = 1500.0 4356 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 4357 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 4358 spin71.pA = 0.9 4359 spin71.dw = 4.0 4360 spin71.kex = 1900.0 4361 4362 # Low precision optimisation. 4363 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4364 4365 # Printout. 4366 print("\n\nOptimised parameters:\n") 4367 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4368 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4369 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4370 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4371 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4372 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4373 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4374 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4375 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4376 4377 # Checks for residue :70. 4378 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 4379 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 4380 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 4381 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 4382 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 4383 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 4384 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 4385 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 4386 4387 # Checks for residue :71. 4388 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 4389 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 4390 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 4391 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 4392 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 4393 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 4394 4395 # Test the conversion to k_AB from kex and pA. 4396 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4397 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4398 4399 # Test the conversion to k_BA from kex and pA. 4400 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4401 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4402 4403
4405 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 4406 4407 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4408 """ 4409 4410 # Base data setup. 4411 self.setup_hansen_cpmg_data(model='IT99') 4412 4413 # Alias the spins. 4414 spin70 = return_spin(":70") 4415 spin71 = return_spin(":71") 4416 4417 # The R20 keys. 4418 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4419 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4420 4421 # Set the initial parameter values. 4422 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4423 spin70.dw = 10.0 4424 spin70.pA = 0.5 4425 spin70.tex = 1000.09 4426 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4427 spin71.dw = 10.0 4428 spin71.pA = 0.95 4429 spin71.tex = 0.1 4430 4431 # Low precision optimisation. 4432 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1) 4433 4434 # Printout. 4435 print("\n\nOptimised parameters:\n") 4436 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4437 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4438 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4439 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4440 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4441 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4442 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4443 4444 # Checks for residue :70. 4445 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4446 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4447 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4448 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4449 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4450 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4451 4452 # Checks for residue :71. 4453 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4454 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4455 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4456 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4457 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4458 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4459 4460
4462 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4463 4464 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4465 """ 4466 4467 # Base data setup. 4468 self.setup_hansen_cpmg_data(model='LM63') 4469 4470 # Alias the spins. 4471 spin70 = return_spin(":70") 4472 spin71 = return_spin(":71") 4473 4474 # The R20 keys. 4475 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4476 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4477 4478 # Set the initial parameter values. 4479 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4480 spin70.phi_ex = 0.3 4481 spin70.kex = 5000.0 4482 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4483 spin71.phi_ex = 0.1 4484 spin71.kex = 2500.0 4485 4486 # Low precision optimisation. 4487 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4488 4489 # Printout. 4490 print("\n\nOptimised parameters:\n") 4491 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4492 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4493 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4494 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4495 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4496 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4497 4498 # Checks for residue :70. 4499 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4500 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4501 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4502 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4503 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4504 4505 # Checks for residue :71. 4506 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4507 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4508 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4509 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4510 4511
4513 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4514 4515 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4516 """ 4517 4518 # Base data setup. 4519 self.setup_hansen_cpmg_data(model='LM63 3-site') 4520 4521 # Alias the spins. 4522 spin70 = return_spin(":70") 4523 spin71 = return_spin(":71") 4524 4525 # The R20 keys. 4526 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4527 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4528 4529 ## Set the initial parameter values. 4530 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4531 spin70.phi_ex_B = 0.14872003058250227 4532 spin70.phi_ex_C = 0.1319419923472704 4533 spin70.kB = 4103.672910444741 4534 spin70.kC = 7029.001690726248 4535 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4536 spin71.phi_ex_B = 0.04013553485505605 4537 spin71.phi_ex_C = 0.020050748406928887 4538 spin71.kB = 4045.3007136121364 4539 spin71.kC = 3586.38798270774 4540 4541 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4542 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4543 4544 # Low precision optimisation. 4545 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4546 4547 # Printout. 4548 print("\n\nOptimised parameters:\n") 4549 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4550 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4551 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4552 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4553 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4554 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4555 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4556 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4557 4558 # Checks for residue :70. 4559 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4560 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4561 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4562 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4563 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4564 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4565 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4566 4567 # Checks for residue :71. 4568 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4569 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4570 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4571 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4572 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4573 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4574 4575
4577 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4578 4579 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4580 """ 4581 4582 # Base data setup. 4583 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4584 4585 # Alias the spins. 4586 spin70 = return_spin(":70") 4587 spin71 = return_spin(":71") 4588 4589 # The R20 keys. 4590 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4591 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4592 4593 # Set the initial parameter values. 4594 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4595 spin70.pA = 0.9897754407 4596 spin70.dw = 5.642418428 4597 spin70.kex = 1743.666375 4598 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4599 spin71.pA = 0.9968032899 4600 spin71.dw = 4.577891393 4601 spin71.kex = 1830.044597 4602 4603 # Low precision optimisation. 4604 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4605 4606 # Printout. 4607 print("\n\nOptimised parameters:\n") 4608 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4609 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4610 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4611 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4612 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4613 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4614 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4615 4616 # Checks for residue :70. 4617 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4618 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4619 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4620 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4621 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4622 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4623 4624 # Checks for residue :71. 4625 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4626 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4627 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4628 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4629 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4630 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4631 4632 # Test the conversion to k_AB from kex and pA. 4633 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4634 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4635 4636 # Test the conversion to k_BA from kex and pA. 4637 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4638 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4639 4640
4642 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4643 4644 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4645 """ 4646 4647 # Base data setup. 4648 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4649 4650 # Alias the spins. 4651 spin70 = return_spin(":70") 4652 spin71 = return_spin(":71") 4653 4654 # The R20 keys. 4655 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4656 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4657 4658 # Set the initial parameter values. 4659 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4660 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4661 spin70.pA = 0.9884781357 4662 spin70.dw = 5.456507396 4663 spin70.kex = 1906.521189 4664 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4665 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4666 spin71.pA = 0.986709616684097 4667 spin71.dw = 2.09245158280905 4668 spin71.kex = 2438.2766211401 4669 4670 # Low precision optimisation. 4671 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4672 4673 # Printout. 4674 print("\n\nOptimised parameters:\n") 4675 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4676 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4677 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4678 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4679 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4680 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4681 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4682 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4683 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4684 4685 # Checks for residue :70. 4686 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4687 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4688 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4689 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4690 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4691 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4692 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4693 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4694 4695 # Checks for residue :71. 4696 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4697 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4698 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4699 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4700 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4701 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4702 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4703 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4704 4705 # Test the conversion to k_AB from kex and pA. 4706 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4707 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4708 4709 # Test the conversion to k_BA from kex and pA. 4710 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4711 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4712 4713
4715 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4716 4717 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4718 """ 4719 4720 # Base data setup. 4721 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4722 4723 # Alias the spins. 4724 spin70 = return_spin(":70") 4725 spin71 = return_spin(":71") 4726 4727 # The R20 keys. 4728 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4729 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4730 4731 # Set the initial parameter values. 4732 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4733 spin70.pA = 0.9 4734 spin70.dw = 6.0 4735 spin70.kex = 1500.0 4736 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4737 spin71.pA = 0.9 4738 spin71.dw = 4.0 4739 spin71.kex = 1900.0 4740 4741 # Low precision optimisation. 4742 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4743 4744 # Printout. 4745 print("\n\nOptimised parameters:\n") 4746 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4747 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4748 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4749 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4750 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4751 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4752 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4753 4754 # Checks for residue :70. 4755 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4756 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4757 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4758 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4759 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4760 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4761 4762 # Checks for residue :71. 4763 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4764 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4765 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4766 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4767 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4768 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4769 4770 # Test the conversion to k_AB from kex and pA. 4771 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4772 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4773 4774 # Test the conversion to k_BA from kex and pA. 4775 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4776 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4777 4778
4780 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4781 4782 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4783 """ 4784 4785 # Base data setup. 4786 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4787 4788 # Alias the spins. 4789 spin70 = return_spin(":70") 4790 spin71 = return_spin(":71") 4791 4792 # The R20 keys. 4793 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4794 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4795 4796 # Set the initial parameter values. 4797 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4798 spin70.pA = 0.9897519798 4799 spin70.dw = 5.644862195 4800 spin70.kex = 1723.820567 4801 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4802 spin71.pA = 0.9968032899 4803 spin71.dw = 4.577891393 4804 spin71.kex = 1830.044597 4805 4806 # Low precision optimisation. 4807 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4808 4809 # Printout. 4810 print("\n\nOptimised parameters:\n") 4811 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4812 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4813 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4814 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4815 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4816 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4817 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4818 4819 # Checks for residue :70. 4820 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4821 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4822 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4823 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4824 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4825 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4826 4827 # Checks for residue :71. 4828 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4829 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4830 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4831 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4832 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4833 4834 # Test the conversion to k_AB from kex and pA. 4835 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4836 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4837 4838 # Test the conversion to k_BA from kex and pA. 4839 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4840 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4841 4842
4844 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4845 4846 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4847 """ 4848 4849 # Base data setup. 4850 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4851 4852 # Alias the spins. 4853 spin70 = return_spin(":70") 4854 spin71 = return_spin(":71") 4855 4856 # The R20 keys. 4857 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4858 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4859 4860 # Set the initial parameter values. 4861 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4862 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4863 spin70.pA = 0.987648082613451 4864 spin70.dw = 5.30679853807572 4865 spin70.kex = 2033.25380420666 4866 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4867 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4868 spin71.pA = 0.992258541625787 4869 spin71.dw = 2.75140650899058 4870 spin71.kex = 2106.60885247431 4871 4872 # Low precision optimisation. 4873 self.interpreter.minimise.calculate() 4874 4875 # Checks for residue :70. 4876 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4877 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4878 4879
4880 - def test_hansen_cpmgfit_input(self):
4881 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4882 4883 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4884 """ 4885 4886 # Load the R2eff results file. 4887 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4888 self.interpreter.results.read(file_name) 4889 self.interpreter.deselect.spin(':4') 4890 4891 # Set up the model. 4892 self.interpreter.relax_disp.select_model('LM63') 4893 4894 # Generate the input files. 4895 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4896 4897 # What the files should contain. 4898 batch_file = ['#! /bin/sh\n', '\n', 'cpmgfit -grid -xmgr -f spin_70_N.in | tee spin_70_N.out\n', 'cpmgfit -grid -xmgr -f spin_71_N.in | tee spin_71_N.out\n'] 4899 spin1 = [ 4900 "title :70@N\n", 4901 "fields 2 11.7432964915 18.7892743865\n", 4902 "function CPMG\n", 4903 "R2 1 10 20\n", 4904 "Rex 0 100.0 100\n", 4905 "Tau 0 10.0 100\n", 4906 "xmgr\n", 4907 "@ xaxis label \"1/tcp (1/ms)\"\n", 4908 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4909 "@ xaxis ticklabel format decimal\n", 4910 "@ yaxis ticklabel format decimal\n", 4911 "@ xaxis ticklabel char size 0.8\n", 4912 "@ yaxis ticklabel char size 0.8\n", 4913 "@ world xmin 0.0\n", 4914 "data\n", 4915 "0.133333 16.045541 0.310925 11.743296 \n", 4916 "0.266667 14.877925 0.303217 11.743296 \n", 4917 "0.400000 14.357820 0.299894 11.743296 \n", 4918 "0.533333 12.664495 0.289532 11.743296 \n", 4919 "0.666667 12.363205 0.287760 11.743296 \n", 4920 "0.800000 11.092532 0.280514 11.743296 \n", 4921 "0.933333 10.566090 0.277619 11.743296 \n", 4922 "1.066667 9.805807 0.273544 11.743296 \n", 4923 "1.200000 9.564301 0.272276 11.743296 \n", 4924 "1.333333 9.015634 0.269442 11.743296 \n", 4925 "1.466667 8.607765 0.267375 11.743296 \n", 4926 "1.600000 8.279997 0.265740 11.743296 \n", 4927 "1.733333 8.474536 0.266708 11.743296 \n", 4928 "1.866667 8.158973 0.265141 11.743296 \n", 4929 "2.000000 7.988631 0.264304 11.743296 \n", 4930 "0.133333 22.224914 0.166231 18.789274 \n", 4931 "0.266667 21.230874 0.162377 18.789274 \n", 4932 "0.400000 20.603704 0.160017 18.789274 \n", 4933 "0.533333 20.327797 0.158996 18.789274 \n", 4934 "0.666667 18.855377 0.153719 18.789274 \n", 4935 "0.800000 18.537531 0.152617 18.789274 \n", 4936 "0.933333 17.508069 0.149138 18.789274 \n", 4937 "1.066667 16.035604 0.144391 18.789274 \n", 4938 "1.200000 15.168192 0.141717 18.789274 \n", 4939 "1.333333 14.431802 0.139516 18.789274 \n", 4940 "1.466667 14.034137 0.138354 18.789274 \n", 4941 "1.600000 12.920148 0.135192 18.789274 \n", 4942 "1.733333 12.653673 0.134456 18.789274 \n", 4943 "1.866667 12.610864 0.134338 18.789274 \n", 4944 "2.000000 11.969303 0.132601 18.789274 \n" 4945 ] 4946 spin2 = [ 4947 "title :71@N\n", 4948 "fields 2 11.7432964915 18.7892743865\n", 4949 "function CPMG\n", 4950 "R2 1 10 20\n", 4951 "Rex 0 100.0 100\n", 4952 "Tau 0 10.0 100\n", 4953 "xmgr\n", 4954 "@ xaxis label \"1/tcp (1/ms)\"\n", 4955 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4956 "@ xaxis ticklabel format decimal\n", 4957 "@ yaxis ticklabel format decimal\n", 4958 "@ xaxis ticklabel char size 0.8\n", 4959 "@ yaxis ticklabel char size 0.8\n", 4960 "@ world xmin 0.0\n", 4961 "data\n", 4962 "0.133333 7.044342 0.170035 11.743296 \n", 4963 "0.266667 6.781033 0.169228 11.743296 \n", 4964 "0.400000 6.467623 0.168279 11.743296 \n", 4965 "0.533333 6.333340 0.167876 11.743296 \n", 4966 "0.666667 6.323238 0.167846 11.743296 \n", 4967 "0.800000 6.005245 0.166902 11.743296 \n", 4968 "0.933333 5.767052 0.166203 11.743296 \n", 4969 "1.066667 5.476968 0.165361 11.743296 \n", 4970 "1.200000 5.469949 0.165341 11.743296 \n", 4971 "1.333333 5.295113 0.164838 11.743296 \n", 4972 "1.466667 5.435648 0.165242 11.743296 \n", 4973 "1.600000 5.410400 0.165169 11.743296 \n", 4974 "1.733333 5.437554 0.165247 11.743296 \n", 4975 "1.866667 5.176844 0.164501 11.743296 \n", 4976 "2.000000 5.227232 0.164644 11.743296 \n", 4977 "0.133333 11.530903 0.081928 18.789274 \n", 4978 "0.266667 10.983094 0.081041 18.789274 \n", 4979 "0.400000 10.512403 0.080294 18.789274 \n", 4980 "0.533333 9.984805 0.079473 18.789274 \n", 4981 "0.666667 9.573163 0.078845 18.789274 \n", 4982 "0.800000 9.178810 0.078253 18.789274 \n", 4983 "0.933333 8.935719 0.077893 18.789274 \n", 4984 "1.066667 8.610147 0.077416 18.789274 \n", 4985 "1.200000 8.353778 0.077045 18.789274 \n", 4986 "1.333333 8.173729 0.076787 18.789274 \n", 4987 "1.466667 8.091607 0.076670 18.789274 \n", 4988 "1.600000 7.706420 0.076126 18.789274 \n", 4989 "1.733333 7.709125 0.076129 18.789274 \n", 4990 "1.866667 7.610856 0.075992 18.789274 \n", 4991 "2.000000 7.552584 0.075911 18.789274 \n", 4992 ] 4993 4994 # Check the batch file. 4995 print("\nChecking the batch file.") 4996 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 4997 lines = file.readlines() 4998 file.close() 4999 for i in range(len(lines)): 5000 self.assertEqual(batch_file[i], lines[i]) 5001 5002 # Check spin :70@N. 5003 print("\nChecking the spin :70@N input file.") 5004 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 5005 lines = file.readlines() 5006 file.close() 5007 for i in range(len(spin1)): 5008 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5009 for i in range(len(lines)): 5010 self.assertEqual(spin1[i], lines[i]) 5011 5012 # Check spin :71@N. 5013 print("\nChecking the spin :71@N input file.") 5014 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 5015 lines = file.readlines() 5016 file.close() 5017 for i in range(len(lines)): 5018 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5019 for i in range(len(spin2)): 5020 self.assertEqual(spin2[i], lines[i])
5021 5022
5024 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 5025 5026 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5027 5028 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 5029 5030 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 5031 - pA = 0.965402506690231, 5032 - dw = 0.805197170133360, 5033 - dwH = -0.595536627771890, 5034 - kex = 569.003663067619868, 5035 - chi2 = 9.297671357952812. 5036 """ 5037 5038 # Base data setup. 5039 self.setup_korzhnev_2005_data(data_list=['DQ']) 5040 5041 # Alias the spin. 5042 spin = return_spin(":9@N") 5043 5044 # The R20 keys. 5045 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5046 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5047 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5048 5049 # Set the initial parameter values. 5050 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 5051 spin.pA = 0.965638501551899 5052 spin.dw = 2.8537583461577 5053 spin.dwH = -0.387633062766635 5054 spin.kex = 573.704033851592 5055 5056 # Low precision optimisation. 5057 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5058 5059 # Monte Carlo simulations. 5060 self.interpreter.monte_carlo.setup(number=3) 5061 self.interpreter.monte_carlo.create_data(method='back_calc') 5062 self.interpreter.monte_carlo.initial_values() 5063 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5064 self.interpreter.monte_carlo.error_analysis() 5065 5066 # Plot the dispersion curves. 5067 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5068 5069 # Save the results. 5070 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5071 5072 # Printout. 5073 print("\n\nOptimised parameters:\n") 5074 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5075 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5076 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5077 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5078 print("%-20s %20.15g" % ("pA", spin.pA)) 5079 print("%-20s %20.15g" % ("dw", spin.dw)) 5080 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5081 print("%-20s %20.15g" % ("kex", spin.kex)) 5082 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5083 5084 # Checks for residue :9. 5085 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2) 5086 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2) 5087 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2) 5088 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4) 5089 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1) 5090 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2) 5091 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3) 5092 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5093 5094
5096 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 5097 5098 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5099 5100 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 5101 5102 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 5103 - pA = 0.930027999814003, 5104 - dw = 4.338620619954370, 5105 - dwH = -0.274250775560818, 5106 - kex = 344.613362916544475, 5107 - chi2 = 10.367733168217050. 5108 """ 5109 5110 # Base data setup. 5111 self.setup_korzhnev_2005_data(data_list=['MQ']) 5112 5113 # Alias the spin. 5114 spin = return_spin(":9@N") 5115 5116 # The R20 keys. 5117 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5118 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5119 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5120 5121 # Set the initial parameter values. 5122 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 5123 spin.pA = 0.930083249288083 5124 spin.dw = 4.33890689462363 5125 spin.dwH = -0.274316585638047 5126 spin.kex = 344.329651956132 5127 5128 # Low precision optimisation. 5129 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5130 5131 # Monte Carlo simulations. 5132 self.interpreter.monte_carlo.setup(number=3) 5133 self.interpreter.monte_carlo.create_data(method='back_calc') 5134 self.interpreter.monte_carlo.initial_values() 5135 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5136 self.interpreter.monte_carlo.error_analysis() 5137 5138 # Plot the dispersion curves. 5139 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5140 5141 # Save the results. 5142 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5143 5144 # Printout. 5145 print("\n\nOptimised parameters:\n") 5146 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5147 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5148 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5149 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5150 print("%-20s %20.15g" % ("pA", spin.pA)) 5151 print("%-20s %20.15g" % ("dw", spin.dw)) 5152 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5153 print("%-20s %20.15g" % ("kex", spin.kex)) 5154 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5155 5156 # Checks for residue :9. 5157 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1) 5158 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1) 5159 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1) 5160 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3) 5161 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2) 5162 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3) 5163 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3) 5164 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5165 5166
5168 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 5169 5170 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5171 5172 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 5173 5174 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 5175 - pA = 0.950003458294991, 5176 - dw = 4.358402855315123, 5177 - kex = 429.906473361926999, 5178 - chi2 = 17.393331915567252. 5179 """ 5180 5181 # Base data setup. 5182 self.setup_korzhnev_2005_data(data_list=['SQ']) 5183 5184 # Alias the spin. 5185 spin = return_spin(":9@N") 5186 5187 # The R20 keys. 5188 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5189 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5190 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5191 5192 # Set the initial parameter values. 5193 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 5194 spin.pA = 0.950310172115387 5195 spin.dw = 4.356737157889636 5196 spin.kex = 433.176323890829849 5197 5198 # Low precision optimisation. 5199 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5200 5201 # Monte Carlo simulations. 5202 self.interpreter.monte_carlo.setup(number=3) 5203 self.interpreter.monte_carlo.create_data(method='back_calc') 5204 self.interpreter.monte_carlo.initial_values() 5205 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5206 self.interpreter.monte_carlo.error_analysis() 5207 5208 # Plot the dispersion curves. 5209 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5210 5211 # Save the results. 5212 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5213 5214 # Printout. 5215 print("\n\nOptimised parameters:\n") 5216 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5217 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5218 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5219 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5220 print("%-20s %20.15g" % ("pA", spin.pA)) 5221 print("%-20s %20.15g" % ("dw", spin.dw)) 5222 print("%-20s %20.15g" % ("kex", spin.kex)) 5223 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5224 5225 # Checks for residue :9. 5226 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2) 5227 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2) 5228 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1) 5229 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3) 5230 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2) 5231 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2) 5232 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5233 5234
5236 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 5237 5238 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5239 5240 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 5241 5242 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 5243 - pA = 0.942452612380140, 5244 - dw = 0.858972784230892, 5245 - dwH = 0.087155962730608, 5246 - kex = 373.219151384798920, 5247 - chi2 = 23.863208106025152. 5248 """ 5249 5250 # Base data setup. 5251 self.setup_korzhnev_2005_data(data_list=['ZQ']) 5252 5253 # Alias the spin. 5254 spin = return_spin(":9@N") 5255 5256 # The R20 keys. 5257 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5258 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5259 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5260 5261 # Set the initial parameter values. 5262 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 5263 spin.pA = 0.942457332074014 5264 spin.dw = 0.850592422908884 5265 spin.dwH = 0.0881272284455416 5266 spin.kex = 372.745483351305 5267 5268 # Low precision optimisation. 5269 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5270 5271 # Monte Carlo simulations. 5272 self.interpreter.monte_carlo.setup(number=3) 5273 self.interpreter.monte_carlo.create_data(method='back_calc') 5274 self.interpreter.monte_carlo.initial_values() 5275 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5276 self.interpreter.monte_carlo.error_analysis() 5277 5278 # Plot the dispersion curves. 5279 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5280 5281 # Save the results. 5282 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5283 5284 # Printout. 5285 print("\n\nOptimised parameters:\n") 5286 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5287 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5288 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5289 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5290 print("%-20s %20.15g" % ("pA", spin.pA)) 5291 print("%-20s %20.15g" % ("dw", spin.dw)) 5292 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5293 print("%-20s %20.15g" % ("kex", spin.kex)) 5294 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5295 5296 # Checks for residue :9. 5297 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2) 5298 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2) 5299 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2) 5300 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4) 5301 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1) 5302 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2) 5303 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3) 5304 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5305 5306
5308 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 5309 5310 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5311 5312 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 5313 5314 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 5315 - pA = 0.936911090448340, 5316 - dw = 4.325314846914845, 5317 - dwH = -0.213870168665628, 5318 - kex = 487.361914835074117, 5319 - chi2 = 14.870371897291138. 5320 """ 5321 5322 # Base data setup. 5323 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 5324 5325 # Alias the spin. 5326 spin = return_spin(":9@N") 5327 5328 # The R20 keys. 5329 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5330 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5331 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5332 5333 # Set the initial parameter values. 5334 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 5335 spin.pA = 0.936884348941701 5336 spin.dw = 4.326454531583964 5337 spin.dwH = -0.214026093221782 5338 spin.kex = 487.043592705469223 5339 5340 # Low precision optimisation. 5341 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 5342 5343 # Monte Carlo simulations. 5344 self.interpreter.monte_carlo.setup(number=3) 5345 self.interpreter.monte_carlo.create_data(method='back_calc') 5346 self.interpreter.monte_carlo.initial_values() 5347 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5348 self.interpreter.monte_carlo.error_analysis() 5349 5350 # Plot the dispersion curves. 5351 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5352 5353 # Save the results. 5354 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5355 5356 # Printout. 5357 print("\n\nOptimised parameters:\n") 5358 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5359 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5360 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5361 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5362 print("%-20s %20.15g" % ("pA", spin.pA)) 5363 print("%-20s %20.15g" % ("dw", spin.dw)) 5364 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5365 print("%-20s %20.15g" % ("kex", spin.kex)) 5366 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5367 5368 # Checks for residue :9. 5369 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4) 5370 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2) 5371 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2) 5372 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4) 5373 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2) 5374 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2) 5375 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4) 5376 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5377 5378
5380 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 5381 5382 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5383 5384 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 5385 5386 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 5387 - pA = 0.946949480545876, 5388 - dwH = -0.265279672133308, 5389 - kex = 406.548178869750700, 5390 - chi2 = 50.400680290545026. 5391 """ 5392 5393 # Base data setup. 5394 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 5395 5396 # Alias the spin. 5397 spin = return_spin(":9@N") 5398 5399 # The R20 keys. 5400 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5401 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5402 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5403 5404 # Set the initial parameter values. 5405 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 5406 spin.pA = 0.946990967372467 5407 spin.dwH = -0.265308128403529 5408 spin.kex = 406.843250675648 5409 5410 # Low precision optimisation. 5411 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5412 5413 # Monte Carlo simulations. 5414 self.interpreter.monte_carlo.setup(number=3) 5415 self.interpreter.monte_carlo.create_data(method='back_calc') 5416 self.interpreter.monte_carlo.initial_values() 5417 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5418 self.interpreter.monte_carlo.error_analysis() 5419 5420 # Plot the dispersion curves. 5421 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5422 5423 # Save the results. 5424 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5425 5426 # Printout. 5427 print("\n\nOptimised parameters:\n") 5428 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5429 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5430 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5431 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5432 print("%-20s %20.15g" % ("pA", spin.pA)) 5433 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5434 print("%-20s %20.15g" % ("kex", spin.kex)) 5435 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5436 5437 # Checks for residue :9. 5438 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2) 5439 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2) 5440 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2) 5441 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4) 5442 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3) 5443 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2) 5444 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5445 5446
5448 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5449 5450 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5451 5452 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5453 5454 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5455 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5456 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5457 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5458 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5459 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5460 - pA = 0.943125351763911, 5461 - dw = 4.421827493809807, 5462 - dwH = -0.272637034755752, 5463 - kex = 360.609744568697238, 5464 - chi2 = 162.589570340050813. 5465 """ 5466 5467 # Base data setup. 5468 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5469 5470 # Alias the spin. 5471 spin = return_spin(":9@N") 5472 5473 # The R20 keys. 5474 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5475 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5476 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5477 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5478 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5479 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5480 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5481 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5482 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5483 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5484 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5485 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5486 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5487 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5488 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5489 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5490 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5491 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5492 5493 # Set the initial parameter values. 5494 spin.r2 = { 5495 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5496 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5497 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5498 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5499 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5500 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5501 } 5502 spin.pA = 0.943129019477673 5503 spin.dw = 4.42209952545181 5504 spin.dwH = -0.27258970590969 5505 spin.kex = 360.516132791038 5506 5507 # Low precision optimisation. 5508 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5509 5510 # Monte Carlo simulations. 5511 self.interpreter.monte_carlo.setup(number=3) 5512 self.interpreter.monte_carlo.create_data(method='back_calc') 5513 self.interpreter.monte_carlo.initial_values() 5514 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5515 self.interpreter.monte_carlo.error_analysis() 5516 5517 # Plot the dispersion curves. 5518 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5519 5520 # Save the results. 5521 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5522 5523 # Printout. 5524 print("\n\nOptimised parameters:\n") 5525 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5526 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5527 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5528 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5529 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5530 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5531 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5532 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5533 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5534 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5535 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5536 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5537 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5538 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5539 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5540 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5541 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5542 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5543 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5544 print("%-20s %20.15g" % ("pA", spin.pA)) 5545 print("%-20s %20.15g" % ("dw", spin.dw)) 5546 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5547 print("%-20s %20.15g" % ("kex", spin.kex)) 5548 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5549 5550 # Checks for residue :9. 5551 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5552 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5553 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5554 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5555 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5556 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5557 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5558 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5559 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5560 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5561 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5562 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5563 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5564 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5565 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5566 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5567 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5568 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5569 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5570 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5571 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5572 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5573 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5574 5575
5577 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5578 5579 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5580 5581 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5582 5583 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5584 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5585 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5586 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5587 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5588 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5589 - pA = 0.943125351763911, 5590 - dw = 4.421827493809807, 5591 - dwH = -0.272637034755752, 5592 - kex = 360.609744568697238, 5593 - chi2 = 162.589570340050813. 5594 """ 5595 5596 # Base data setup. 5597 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5598 5599 # Alias the spin. 5600 spin = return_spin(":9@N") 5601 5602 # The R20 keys. 5603 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5604 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5605 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5606 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5607 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5608 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5609 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5610 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5611 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5612 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5613 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5614 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5615 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5616 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5617 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5618 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5619 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5620 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5621 5622 # Set the initial parameter values. 5623 spin.r2 = { 5624 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5625 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5626 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5627 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5628 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5629 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5630 } 5631 spin.pA = 0.943129019477673 5632 spin.dw = 4.42209952545181 5633 spin.dwH = -0.27258970590969 5634 spin.kex = 360.516132791038 5635 5636 # Calc the chi2 values at these parameters. 5637 self.interpreter.minimise.calculate(verbosity=1) 5638 5639 # Printout. 5640 print("\n\nOptimised parameters:\n") 5641 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5642 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5643 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5644 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5645 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5646 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5647 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5648 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5649 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5650 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5651 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5652 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5653 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5654 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5655 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5656 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5657 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5658 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5659 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5660 print("%-20s %20.15g" % ("pA", spin.pA)) 5661 print("%-20s %20.15g" % ("dw", spin.dw)) 5662 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5663 print("%-20s %20.15g" % ("kex", spin.kex)) 5664 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5665 5666 # Checks for residue :9. 5667 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5668 5669
5671 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5672 5673 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5674 5675 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5676 5677 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5678 - 0.483 0.89623903 2.4503699912708878 5679 - 0.545 1.1694838 5680 - 0.545 1.1761503 5681 - 0.622 1.294 5682 - 0.669 1.5176493 5683 - 0.722 1.6238791 5684 - 0.813 1.9395758 5685 - 1.011 2.3558415 10.547000429321157 5686 """ 5687 5688 # Base data setup. 5689 model = 'TSMFK01' 5690 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5691 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5692 5693 # Alias the spins. 5694 res61L = cdp.mol[0].res[0].spin[0] 5695 5696 # The R20 keys. 5697 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5698 5699 # Set the initial parameter values. 5700 res61L.r2a = {r20_key1: 8.0} 5701 res61L.dw = 6.5 5702 res61L.k_AB = 2.5 5703 5704 # Low precision optimisation. 5705 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5706 5707 # Start testing all possible combinations of graphs. 5708 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5709 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5710 interpolate_types = [INTERPOLATE_DISP] 5711 5712 # Write to temp folder. 5713 result_dir_name = ds.tmpdir 5714 result_folders = [model] 5715 spin_id = ":61@N" 5716 5717 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5718 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5719 5720 for result_folder in result_folders: 5721 for y_axis in y_axis_types: 5722 for x_axis in x_axis_types: 5723 for interpolate in interpolate_types: 5724 # Determine file name: 5725 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5726 5727 # Make the file name. 5728 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5729 5730 # Write the curves. 5731 dir = result_dir_name+sep+result_folder 5732 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5733 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5734 5735 # Get the file path. 5736 file_path = get_file_path(file_name, dir) 5737 5738 # Test the plot file exists. 5739 print("Testing file access to graph: %s"%file_path) 5740 self.assert_(access(file_path, F_OK)) 5741 5742 # Now open, and compare content, line by line. 5743 file_prod = open(file_path) 5744 lines_prod = file_prod.readlines() 5745 file_prod.close() 5746 5747 # Define file to compare against. 5748 dir_comp = data_path+sep+result_folder 5749 file_path_comp = get_file_path(file_name, dir_comp) 5750 file_comp = open(file_path_comp) 5751 lines_comp = file_comp.readlines() 5752 file_comp.close() 5753 5754 ## Assert number of lines is equal. 5755 self.assertEqual(len(lines_prod), len(lines_comp)) 5756 for j in range(len(lines_prod)): 5757 # Make the string test 5758 first_char = lines_prod[j][0] 5759 if first_char in ["@", "&"]: 5760 self.assertEqual(lines_prod[j], lines_comp[j]) 5761 else: 5762 # Split string in x, y, error. 5763 # The error would change per run. 5764 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5765 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5766 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5767 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5768 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5769 5770
5772 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5773 5774 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5775 """ 5776 5777 # Base data setup. 5778 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5779 5780 # Alias the spins. 5781 res61L = cdp.mol[0].res[0].spin[0] 5782 5783 # The R20 keys. 5784 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5785 5786 # Set the initial parameter values. 5787 res61L.r2 = {r20_key1: 8.0} 5788 res61L.pA = 0.9 5789 res61L.dw = 6.0 5790 res61L.kex = 600.0 5791 5792 # Low precision optimisation. 5793 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5794 5795 # Printout. 5796 print("\n\nOptimised parameters:\n") 5797 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5798 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5799 print("%-20s %20.15g" % ("pA", res61L.pA)) 5800 print("%-20s %20.15g" % ("dw", res61L.dw)) 5801 print("%-20s %20.15g" % ("kex", res61L.kex)) 5802 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5803 5804 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5805 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5806 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5807 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5808 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5809 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5810 5811 # Test the conversion to k_AB from kex and pA. 5812 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5813 5814 # Test the conversion to k_BA from kex and pA. 5815 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5816 5817
5819 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5820 5821 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5822 """ 5823 5824 # Base data setup. 5825 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5826 5827 # Alias the spins. 5828 res61L = cdp.mol[0].res[0].spin[0] 5829 5830 # The R20 keys. 5831 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5832 5833 # Set the initial parameter values. 5834 res61L.r2a = {r20_key1: 8.0} 5835 res61L.r2b = {r20_key1: 105.0} 5836 res61L.pA = 0.9 5837 res61L.dw = 6.0 5838 res61L.kex = 500.0 5839 5840 # Low precision optimisation. 5841 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5842 5843 # Printout. 5844 print("\n\nOptimised parameters:\n") 5845 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5846 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5847 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5848 print("%-20s %20.15g" % ("pA", res61L.pA)) 5849 print("%-20s %20.15g" % ("dw", res61L.dw)) 5850 print("%-20s %20.15g" % ("kex", res61L.kex)) 5851 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5852 5853 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5854 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5855 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5856 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5857 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5858 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5859 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5860 5861
5863 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5864 5865 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5866 5867 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5868 5869 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5870 - 0.483 0.89623903 2.4503699912708878 5871 - 0.545 1.1694838 5872 - 0.545 1.1761503 5873 - 0.622 1.294 5874 - 0.669 1.5176493 5875 - 0.722 1.6238791 5876 - 0.813 1.9395758 5877 - 1.011 2.3558415 10.547000429321157 5878 """ 5879 5880 # Base data setup. 5881 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5882 5883 # Alias the spins. 5884 res61L = cdp.mol[0].res[0].spin[0] 5885 5886 # The R20 keys. 5887 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5888 5889 # Set the initial parameter values. 5890 res61L.r2a = {r20_key1: 8.0} 5891 res61L.dw = 6.5 5892 res61L.k_AB = 2.5 5893 5894 # Low precision optimisation. 5895 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5896 5897 # Printout. 5898 print("\n\nOptimised parameters:\n") 5899 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5900 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5901 print("%-20s %20.15g" % ("dw", res61L.dw)) 5902 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5903 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5904 5905 # Checks for residue :61. Reference values from paper 5906 5907 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5908 5909
5911 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5912 5913 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride). 5914 5915 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably. 5916 5917 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C: 5918 5919 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5920 - k_AB = 11.3 +/- 0.7 s^-1, 5921 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5922 - R2 = 8.0 +/- 0.5 s^-1. 5923 5924 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5925 - k_AB = 10.55 +/- 0.08 s^-1, 5926 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5927 - R2 = 8.4 +/- 0.3 s^-1. 5928 5929 Conversion of paper results to relax results is performed by: 5930 5931 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm. 5932 5933 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5934 5935 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5936 - 0.483 0.89623903 2.4503699912708878 5937 - 0.545 1.1694838 5938 - 0.545 1.1761503 5939 - 0.622 1.294 5940 - 0.669 1.5176493 5941 - 0.722 1.6238791 5942 - 0.813 1.9395758 5943 - 1.011 2.3558415 10.547000429321157 5944 """ 5945 5946 # Base data setup. 5947 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 5948 5949 # Alias the spins. 5950 res61L = cdp.mol[0].res[0].spin[0] 5951 5952 # The R20 keys. 5953 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 5954 5955 # Set the initial parameter values. 5956 res61L.r2a = {r20_key1: 8.0} 5957 res61L.dw = 6.5 5958 res61L.k_AB = 11.0 5959 5960 # Low precision optimisation. 5961 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5962 5963 # Printout. 5964 print("\n\nOptimised parameters:\n") 5965 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5966 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5967 print("%-20s %20.15g" % ("dw", res61L.dw)) 5968 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5969 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5970 5971 # Checks for residue :61. Reference values from paper 5972 5973 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 5974 self.assertAlmostEqual(res61L.dw, 6.41, 0) 5975 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
5976 5977
5978 - def test_lm63_3site_synthetic(self):
5979 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 5980 5981 # The path to the data files. 5982 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 5983 5984 # Load the state file. 5985 self.interpreter.reset() 5986 self.interpreter.state.load(data_path+sep+'r2eff_values') 5987 5988 # A new data pipe. 5989 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 5990 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 5991 5992 # Set up the model data. 5993 self.interpreter.relax_disp.select_model(model='LM63 3-site') 5994 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 5995 self.interpreter.spin.isotope('15N') 5996 5997 # Alias the spins. 5998 spin1 = return_spin(":1") 5999 spin2 = return_spin(":2") 6000 6001 # The R20 keys. 6002 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 6003 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 6004 6005 # Manually set the parameter values. 6006 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 6007 spin1.phi_ex_B = 0.1 6008 spin1.phi_ex_C = 0.5 6009 spin1.kB = 1500.0 6010 spin1.kC = 2500.0 6011 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 6012 spin2.phi_ex_B = 0.1 6013 spin2.phi_ex_C = 0.5 6014 spin2.kB = 1500.0 6015 spin2.kC = 2500.0 6016 6017 # Low precision optimisation. 6018 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 6019 6020 # Monte Carlo simulations. 6021 self.interpreter.monte_carlo.setup(number=3) 6022 self.interpreter.monte_carlo.create_data(method='back_calc') 6023 self.interpreter.monte_carlo.initial_values() 6024 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1) 6025 self.interpreter.monte_carlo.error_analysis() 6026 6027 # Save the results. 6028 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 6029 6030 # The model checks. 6031 print("\n\nOptimised parameters:\n") 6032 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 6033 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 6034 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 6035 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 6036 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 6037 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 6038 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 6039 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 6040 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 6041 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 6042 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6043 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6044 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6045 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6046 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 6047 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 6048 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 6049 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6050 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6051 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6052 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6053 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
6054 6055
6056 - def test_m61_data_to_m61(self):
6057 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 6058 6059 # Fixed time variable. 6060 ds.fixed = True 6061 6062 # Execute the script. 6063 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6064 6065 # The original parameters. 6066 i0 = [100000.0, 20000.0] 6067 r1rho_prime = [2.25, 24.0] 6068 pA = 0.7 6069 kex = 1000.0 6070 delta_omega = [1.0, 2.0] 6071 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6072 phi_ex = [] 6073 for i in range(2): 6074 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6075 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6076 6077 # Switch to the 'R2eff' model data pipe, then check for each spin. 6078 self.interpreter.pipe.switch('R2eff - relax_disp') 6079 spin_index = 0 6080 for spin, spin_id in spin_loop(return_id=True): 6081 # Printout. 6082 print("\nSpin %s." % spin_id) 6083 6084 # Check the fitted parameters. 6085 for i in range(len(keys)): 6086 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6087 6088 # Increment the spin index. 6089 spin_index += 1 6090 6091 # The R20 keys. 6092 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6093 6094 # Switch to the 'M61' model data pipe, then check for each spin. 6095 self.interpreter.pipe.switch('M61 - relax_disp') 6096 spin_index = 0 6097 for spin, spin_id in spin_loop(return_id=True): 6098 # Printout. 6099 print("\nSpin %s." % spin_id) 6100 6101 # Check the fitted parameters. 6102 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6103 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6104 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6105 6106 # Increment the spin index. 6107 spin_index += 1
6108 6109
6110 - def test_m61_exp_data_to_m61(self):
6111 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 6112 6113 # Fixed time variable. 6114 ds.fixed = False 6115 6116 # Single spin optimisation. 6117 ds.single = True 6118 6119 # Execute the script. 6120 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6121 6122 # The original parameters. 6123 i0 = [100000.0, 20000.0] 6124 r1rho_prime = [2.25, 24.0] 6125 pA = 0.7 6126 kex = 1000.0 6127 delta_omega = [1.0, 2.0] 6128 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6129 phi_ex = [] 6130 for i in range(2): 6131 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6132 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6133 6134 # Switch to the 'R2eff' model data pipe, then check for each spin. 6135 self.interpreter.pipe.switch('R2eff - relax_disp') 6136 spin_index = 0 6137 for spin, spin_id in spin_loop(return_id=True): 6138 # Printout. 6139 print("\nSpin %s." % spin_id) 6140 6141 # Check the fitted parameters. 6142 for i in range(len(keys)): 6143 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6144 6145 # Increment the spin index. 6146 spin_index += 1 6147 6148 # The R20 keys. 6149 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6150 6151 # Switch to the 'M61' model data pipe, then check for each spin. 6152 self.interpreter.pipe.switch('M61 - relax_disp') 6153 spin_index = 0 6154 for spin, spin_id in spin_loop(return_id=True): 6155 # Printout. 6156 print("\nSpin %s." % spin_id) 6157 6158 # Check the fitted parameters. 6159 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6160 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6161 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6162 6163 # Increment the spin index. 6164 spin_index += 1
6165 6166
6167 - def test_m61b_data_to_m61b(self):
6168 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 6169 6170 # Execute the script. 6171 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py') 6172 6173 # The original parameters. 6174 i0 = [100000.0, 20000.0] 6175 r1rho_prime = [10.0, 24.0] 6176 pA = 0.95 6177 kex = 2000.0 6178 delta_omega = [1.0, 2.0] 6179 6180 # The R20 keys. 6181 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6182 6183 # Switch to the 'M61 skew' model data pipe, then check for each spin. 6184 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 6185 spin_index = 0 6186 for spin, spin_id in spin_loop(return_id=True): 6187 # Printout. 6188 print("\nSpin %s." % spin_id) 6189 6190 # Check the fitted parameters. 6191 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6192 self.assertAlmostEqual(spin.pA, pA, 2) 6193 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 6194 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6195 6196 # Increment the spin index. 6197 spin_index += 1
6198 6199
6201 """Test that all models which can nest, have all their parameters converted.""" 6202 6203 # Set the experiment type. 6204 cdp.exp_type_list = EXP_TYPE_LIST 6205 6206 # Get info for all models. 6207 all_models_info = models_info(models=MODEL_LIST_FULL) 6208 6209 # Loop over all models. 6210 print("Printing the listed of nested models for each model.") 6211 print("#########################################") 6212 for model_info in all_models_info: 6213 print("%s"%model_info.model), 6214 print("<-"), 6215 nest_list = model_info.nest_list 6216 if nest_list == None: 6217 nest_list = ["None"] 6218 print(', '.join(map(str, nest_list))) 6219 6220 # Skip if there is no model to nest from. 6221 if nest_list == ["None"]: 6222 continue 6223 6224 # Assign params to variable. 6225 model_params = model_info.params 6226 6227 # Now loop over the nested models. 6228 for nested_model in nest_list: 6229 # Get the params for the nested model. 6230 nested_model_params = MODEL_PARAMS[nested_model] 6231 6232 # Get the dictionary of parameter conversion. 6233 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 6234 6235 # Test the number of elements in the dictionary. 6236 self.assertEqual(len(par_dic), len(model_params)) 6237 6238 # Loop over dictionary. 6239 for param in par_dic: 6240 if param != par_dic[param]: 6241 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param)) 6242 self.assertNotEqual(par_dic[param], None)
6243 6244
6245 - def test_ns_mmq_3site(self):
6246 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 6247 6248 # Execute the script. 6249 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 6250 6251 # Check the chi-squared value. 6252 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6253 6254
6255 - def test_ns_mmq_3site_linear(self):
6256 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6257 6258 # Execute the script. 6259 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py') 6260 6261 # Check the chi-squared value. 6262 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6263 6264
6265 - def test_ns_r1rho_3site(self):
6266 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 6267 6268 # Execute the script. 6269 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 6270 6271 # Check the chi-squared value. 6272 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6273 6274
6275 - def test_ns_r1rho_3site_linear(self):
6276 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6277 6278 # Execute the script. 6279 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py') 6280 6281 # Check the chi-squared value. 6282 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6283 6284
6285 - def test_repeat_cpmg(self):
6286 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg. 6287 6288 U{task #7826<https://gna.org/task/index.php?7826>}. Write an python class for the repeated analysis of dispersion data. 6289 """ 6290 6291 # Reset. 6292 self.interpreter.reset() 6293 6294 # Define base path to files. 6295 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1' 6296 6297 # Setup dictionary with settings. 6298 sdic = {} 6299 6300 # Spectrometer frqs in list. 6301 sfrq_1 = 499.86214 6302 sfrq_2 = 599.8908587 6303 sfrqs = [sfrq_1, sfrq_2] 6304 6305 # Store in dictionary. 6306 sdic['sfrqs'] = sfrqs 6307 6308 # Store unit for frq. 6309 sdic['sfrq_unit'] = 'MHz' 6310 6311 # Store exp_type 6312 sdic['exp_type'] = 'SQ CPMG' 6313 6314 # Store spin isotope 6315 sdic['isotope'] = '15N' 6316 6317 # How intensity was measured. 6318 sdic['int_method'] = 'height' 6319 6320 # Define the time for result directory. 6321 sdic['time'] = '2014_09' 6322 6323 # Initialize frq dics. 6324 for frq in sfrqs: 6325 key = DIC_KEY_FORMAT % (frq) 6326 sdic[key] = {} 6327 6328 # Set keys. 6329 e_1 = DIC_KEY_FORMAT % (sfrq_1) 6330 e_2 = DIC_KEY_FORMAT % (sfrq_2) 6331 6332 # Store time T2. 6333 sdic[e_1]['time_T2'] = 0.04 6334 sdic[e_2]['time_T2'] = 0.06 6335 6336 # Set ncyc. 6337 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0]) 6338 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22]) 6339 6340 # Calculate the cpmg_frq and store. 6341 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2'] 6342 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2'] 6343 6344 # Define peak lists. 6345 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6346 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6347 sdic[e_1]['peaks_folder'] = peaks_folder_1 6348 sdic[e_2]['peaks_folder'] = peaks_folder_2 6349 6350 # Define folder to all rmsd files. 6351 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data' 6352 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data' 6353 sdic[e_1]['rmsd_folder'] = rmsd_folder_1 6354 sdic[e_2]['rmsd_folder'] = rmsd_folder_2 6355 6356 # Define temporary folder. 6357 sdic['results_dir'] = self.tmpdir 6358 6359 # Setup class with data. 6360 RDR = Relax_disp_rep(sdic) 6361 6362 # Setup base information. 6363 RDR.set_base_cpmg(method='FT', glob_ini=128) 6364 6365 methods = ['FT', 'MDD'] 6366 #methods = ['FT'] 6367 6368 # Set the intensity. 6369 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=False, set_rep=True) 6370 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=True, set_rep=False) 6371 6372 # Try plot some intensity correlations. 6373 if True: 6374 selection = None 6375 6376 # Now make a spin selection. 6377 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection) 6378 6379 # For mdd 6380 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6381 6382 # Plot correlation of intensity 6383 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]] 6384 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]] 6385 corr_data = [fig1, fig2] 6386 6387 write_stats = True 6388 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6389 6390 # Open stat file. 6391 if write_stats: 6392 for i, corr_data_i in enumerate(corr_data): 6393 data, methods, glob_inis = corr_data[i] 6394 data_x, data_y = data 6395 method_x, method_y = methods 6396 glob_ini_x, glob_ini_y = glob_inis 6397 x = data_x[str(glob_ini_x)]['peak_intensity_arr'] 6398 np = len(x) 6399 6400 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6401 6402 if selection == None: 6403 file_name = file_name_ini + '_all.txt' 6404 else: 6405 file_name = file_name_ini + '_sel.txt' 6406 path = RDR.results_dir 6407 data = extract_data(file=file_name, dir=path) 6408 6409 # Loop over the lines. 6410 for i, data_i in enumerate(data): 6411 print(i, data_i) 6412 6413 6414 # Try plot some intensity statistics. 6415 if True: 6416 # Collect r2eff values. 6417 selections = [None, ':2,3'] 6418 for selection in selections: 6419 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection) 6420 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6421 6422 # Get R2eff stats. 6423 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126]) 6424 6425 ## Plot R2eff stats 6426 write_stats = True 6427 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats) 6428 6429 # Open stat file. 6430 if write_stats: 6431 if selection == None: 6432 file_name = 'int_stat_all.txt' 6433 else: 6434 file_name = 'int_stat_sel.txt' 6435 path = RDR.results_dir 6436 data = extract_data(file=file_name, dir=path) 6437 6438 # Loop over the lines. 6439 for i, data_i in enumerate(data): 6440 print(i, data_i) 6441 6442 6443 # Try write some R2eff correlations. 6444 if True: 6445 selection = None 6446 # Collect r2eff values. 6447 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6448 6449 # For all spins, mdd 6450 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6451 6452 # Plot correlation of intensity 6453 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]] 6454 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]] 6455 corr_data = [fig1, fig2] 6456 6457 write_stats = True 6458 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6459 6460 # Open stat file. 6461 if write_stats: 6462 for i, corr_data_i in enumerate(corr_data): 6463 data, methods, glob_inis = corr_data[i] 6464 data_x, data_y = data 6465 method_x, method_y = methods 6466 glob_ini_x, glob_ini_y = glob_inis 6467 x = data_x[str(glob_ini_x)]['r2eff_arr'] 6468 np = len(x) 6469 6470 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6471 6472 if selection == None: 6473 file_name = file_name_ini + '_all.txt' 6474 else: 6475 file_name = file_name_ini + '_sel.txt' 6476 path = RDR.results_dir 6477 data = extract_data(file=file_name, dir=path) 6478 6479 # Loop over the lines. 6480 for i, data_i in enumerate(data): 6481 print(i, data_i) 6482 6483 6484 # Try plot some R2eff statistics. 6485 if True: 6486 # Collect r2eff values. 6487 selections = [None, ':2,3'] 6488 for selection in selections: 6489 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6490 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6491 6492 # Get R2eff stats. 6493 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126]) 6494 6495 ## Plot R2eff stats 6496 write_stats = True 6497 RDR.plot_r2eff_stat(r2eff_stat_dic=r2eff_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6498 6499 # Open stat file. 6500 if write_stats: 6501 if selection == None: 6502 file_name = 'r2eff_stat_all.txt' 6503 else: 6504 file_name = 'r2eff_stat_sel.txt' 6505 path = RDR.results_dir 6506 data = extract_data(file=file_name, dir=path) 6507 6508 # Loop over the lines. 6509 for i, data_i in enumerate(data): 6510 print(i, data_i) 6511 6512 6513 # Do minimisation individual. 6514 if True: 6515 methods = ['FT', 'MDD'] 6516 # Now calculate R2eff. 6517 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6518 6519 min_methods = [['FT'], ['MDD']] 6520 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6521 6522 #min_methods = [['FT']] 6523 #min_list_glob_ini = [[128]] 6524 #selection = ':2,3' 6525 selection = None 6526 6527 for i, methods in enumerate(min_methods): 6528 list_glob_ini = min_list_glob_ini[i] 6529 6530 if True: 6531 # First get data. 6532 if True: 6533 # First load all data. 6534 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6535 6536 # Then set R20 6537 if True: 6538 # Set R20 from min R2eff in preparation for Grid search. 6539 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6540 6541 # Check and print parameters. 6542 if True: 6543 # Print for pipe name 6544 method = methods[0] 6545 glob_ini = list_glob_ini[0] 6546 6547 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini) 6548 RDR.spin_display_params(pipe_name=test_pipe_name) 6549 6550 # Then Grid search. 6551 if True: 6552 # Do Grid search. 6553 RDR.minimise_grid_search(inc=4, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6554 6555 # Then Minimise. 6556 if True: 6557 # Minimise 6558 RDR.opt_max_iterations = int(1e2) 6559 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6560 6561 #print asd 6562 6563 # Plot statistics. 6564 # Try plot some minimisation correlations. 6565 if True: 6566 selections = [None, ':2,3'] 6567 for selection in selections: 6568 # Collect param values. 6569 analysis = 'min_ind' 6570 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6571 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6572 6573 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6574 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6575 corr_data = [fig1, fig2] 6576 6577 write_stats = True 6578 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6579 6580 # Open stat file. 6581 if write_stats: 6582 for i, corr_data_i in enumerate(corr_data): 6583 data, methods, glob_inis = corr_data[i] 6584 data_x, data_y = data 6585 method_x, method_y = methods 6586 glob_ini_x, glob_ini_y = glob_inis 6587 6588 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6589 6590 if selection == None: 6591 file_name = file_name_ini + '_all.txt' 6592 else: 6593 file_name = file_name_ini + '_sel.txt' 6594 path = RDR.results_dir 6595 data = extract_data(file=file_name, dir=path) 6596 6597 # Loop over the lines. 6598 for i, data_i in enumerate(data): 6599 print(i, data_i) 6600 6601 # Try plot some minimisation statistics. 6602 if True: 6603 # Collect param values. 6604 #selections = [None, ':2,3'] 6605 selections = [None, ':2,3'] 6606 for selection in selections: 6607 analysis = 'min_ind' 6608 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6609 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6610 6611 # Get param stats. 6612 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6613 6614 ## Plot R2eff stats 6615 write_stats = True 6616 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6617 6618 # Open stat file. 6619 if write_stats: 6620 if selection == None: 6621 file_name = '%s_stat_all.txt' % (analysis) 6622 else: 6623 file_name = '%s_stat_sel.txt' % (analysis) 6624 path = RDR.results_dir 6625 data = extract_data(file=file_name, dir=path) 6626 6627 # Loop over the lines. 6628 for i, data_i in enumerate(data): 6629 print(i, data_i) 6630 6631 6632 # Do minimisation clustered. 6633 if True: 6634 methods = ['FT', 'MDD'] 6635 # Now calculate R2eff. 6636 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6637 6638 min_methods = [['FT'], ['MDD']] 6639 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6640 6641 #min_methods = [['FT']] 6642 #min_list_glob_ini = [[128]] 6643 selection = ':2,3' 6644 6645 for i, methods in enumerate(min_methods): 6646 list_glob_ini = min_list_glob_ini[i] 6647 6648 if True: 6649 # First get data. 6650 if True: 6651 # First load all data. 6652 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6653 6654 # Then select spins. 6655 if True: 6656 # Deselect all spins. 6657 RDR.deselect_all(methods=methods, model='setup', model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6658 6659 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6660 6661 # Then preset values. 6662 if True: 6663 # Set k_AB for Grid search. 6664 RDR.value_set(methods=methods, val=1000., param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6665 RDR.value_set(methods=methods, val=0.95, param='pA', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6666 6667 # Then set R20 6668 if True: 6669 # Set R20 from min R2eff in preparation for Grid search. 6670 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6671 6672 # Check and print parameters. 6673 if True: 6674 # Print for pipe name 6675 method = methods[0] 6676 glob_ini = list_glob_ini[0] 6677 6678 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini) 6679 RDR.spin_display_params(pipe_name=test_pipe_name) 6680 6681 # Then Grid search. 6682 if True: 6683 # Do Grid search. 6684 RDR.minimise_grid_search(inc=200, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid', analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True) 6685 6686 # Then cluster spins. 6687 if True: 6688 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True) 6689 6690 # Then Minimise. 6691 if True: 6692 # Minimise 6693 RDR.opt_max_iterations = int(1e2) 6694 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False) 6695 6696 # Plot statistics. 6697 # Try plot some minimisation correlations. 6698 if True: 6699 selection = ':2,3' 6700 # Collect param values. 6701 analysis = 'min' 6702 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6703 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6704 6705 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6706 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6707 corr_data = [fig1, fig2] 6708 6709 write_stats = True 6710 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6711 6712 # Open stat file. 6713 if write_stats: 6714 for i, corr_data_i in enumerate(corr_data): 6715 data, methods, glob_inis = corr_data[i] 6716 data_x, data_y = data 6717 method_x, method_y = methods 6718 glob_ini_x, glob_ini_y = glob_inis 6719 6720 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6721 6722 if selection == None: 6723 file_name = file_name_ini + '_all.txt' 6724 else: 6725 file_name = file_name_ini + '_sel.txt' 6726 path = RDR.results_dir 6727 data = extract_data(file=file_name, dir=path) 6728 6729 # Loop over the lines. 6730 for i, data_i in enumerate(data): 6731 print(i, data_i) 6732 6733 # Try plot some minimisation statistics. 6734 if True: 6735 # Collect param values. 6736 selections = [':2,3'] 6737 for selection in selections: 6738 analysis = 'min' 6739 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6740 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6741 6742 # Get param stats. 6743 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6744 6745 ## Plot R2eff stats 6746 write_stats = True 6747 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6748 6749 # Open stat file. 6750 if write_stats: 6751 if selection == None: 6752 file_name = '%s_stat_all.txt' % (analysis) 6753 else: 6754 file_name = '%s_stat_sel.txt' % (analysis) 6755 path = RDR.results_dir 6756 data = extract_data(file=file_name, dir=path) 6757 6758 # Loop over the lines. 6759 for i, data_i in enumerate(data): 6760 print(i, data_i)
6761 6762 6763
6764 - def test_r1rho_kjaergaard_auto(self):
6765 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6766 6767 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6768 6769 This uses the automatic analysis. 6770 6771 """ 6772 6773 # Cluster residues 6774 cluster_ids = [ 6775 ":13@N", 6776 ":15@N", 6777 ":16@N", 6778 ":25@N", 6779 ":26@N", 6780 ":28@N", 6781 ":39@N", 6782 ":40@N", 6783 ":41@N", 6784 ":43@N", 6785 ":44@N", 6786 ":45@N", 6787 ":49@N", 6788 ":52@N", 6789 ":53@N"] 6790 6791 # Load the data. 6792 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6793 6794 # Test some of the sequence. 6795 self.assertEqual(len(cdp.mol), 1) 6796 self.assertEqual(cdp.mol[0].name, None) 6797 self.assertEqual(len(cdp.mol[0].res), 48) 6798 6799 # Test the chemical shift data. 6800 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 6801 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 6802 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 6803 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048] 6804 6805 i = 0 6806 for spin, spin_id in spin_loop(return_id=True): 6807 # Check the chemical shift. 6808 self.assertEqual(spin.chemical_shift, cs[i]) 6809 6810 # Increment the index. 6811 i += 1 6812 6813 # Initialize counter 6814 i = 0 6815 j = 0 6816 # Count instances of select/deselect 6817 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6818 if curspin.select == True: 6819 i += 1 6820 if curspin.select == False: 6821 j += 1 6822 6823 # Test number of selected/deselected spins. 6824 self.assertEqual(i, len(cluster_ids)) 6825 self.assertEqual(j, 48-len(cluster_ids)) 6826 6827 # Check the initial setup. 6828 self.assertEqual(cdp.mol[0].res[7].num, 13) 6829 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 6830 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 6831 6832 self.assertEqual(cdp.mol[0].res[9].num, 15) 6833 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 6834 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 6835 6836 self.assertEqual(cdp.mol[0].res[10].num, 16) 6837 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 6838 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 6839 6840 self.assertEqual(cdp.mol[0].res[16].num, 25) 6841 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 6842 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 6843 6844 self.assertEqual(cdp.mol[0].res[17].num, 26) 6845 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 6846 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 6847 6848 self.assertEqual(cdp.mol[0].res[19].num, 28) 6849 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 6850 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 6851 6852 self.assertEqual(cdp.mol[0].res[29].num, 39) 6853 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 6854 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 6855 6856 self.assertEqual(cdp.mol[0].res[30].num, 40) 6857 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 6858 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 6859 6860 self.assertEqual(cdp.mol[0].res[31].num, 41) 6861 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 6862 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 6863 6864 self.assertEqual(cdp.mol[0].res[33].num, 43) 6865 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 6866 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 6867 6868 self.assertEqual(cdp.mol[0].res[34].num, 44) 6869 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 6870 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 6871 6872 self.assertEqual(cdp.mol[0].res[35].num, 45) 6873 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 6874 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 6875 6876 self.assertEqual(cdp.mol[0].res[38].num, 49) 6877 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 6878 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 6879 6880 self.assertEqual(cdp.mol[0].res[41].num, 52) 6881 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 6882 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 6883 6884 self.assertEqual(cdp.mol[0].res[42].num, 53) 6885 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 6886 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 6887 6888 # The dispersion models. 6889 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 6890 6891 # The grid search size (the number of increments per dimension). 6892 GRID_INC = 4 6893 6894 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6895 MC_NUM = 3 6896 6897 # Model selection technique. 6898 MODSEL = 'AIC' 6899 6900 # Execute the auto-analysis (fast). 6901 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6902 OPT_FUNC_TOL = 1e-1 6903 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6904 OPT_MAX_ITERATIONS = 1000 6905 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6906 6907 result_dir_name = ds.tmpdir 6908 6909 # Make all spins free 6910 for curspin in cluster_ids: 6911 self.interpreter.relax_disp.cluster('free spins', curspin) 6912 # Shut them down 6913 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6914 6915 # Select only a subset of spins for global fitting 6916 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 6917 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 6918 6919 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 6920 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 6921 6922 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6923 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 6924 6925 # Run the analysis. 6926 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6927 6928 # Check the kex value of residue 52 6929 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 6930 6931 # Print results for each model. 6932 print("\n\n################") 6933 print("Printing results") 6934 print("################\n") 6935 for model in MODELS: 6936 # Skip R2eff model. 6937 if model == MODEL_R2EFF: 6938 continue 6939 6940 # Switch to pipe. 6941 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 6942 print("\nModel: %s" % (model)) 6943 6944 # Loop over the spins. 6945 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6946 # Generate spin string. 6947 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 6948 6949 # Loop over the parameters. 6950 print("Optimised parameters for spin: %s" % (spin_string)) 6951 for param in cur_spin.params + ['chi2']: 6952 # Get the value. 6953 if param in ['r1', 'r2']: 6954 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 6955 # Generate the R20 key. 6956 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 6957 6958 # Get the value. 6959 value = getattr(cur_spin, param)[r20_key] 6960 6961 # Print value. 6962 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6963 6964 # For all other parameters. 6965 else: 6966 # Get the value. 6967 value = getattr(cur_spin, param) 6968 6969 # Print value. 6970 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6971 6972 # Print the final pipe. 6973 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 6974 print("\nFinal pipe")
6975 6976
6978 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 6979 6980 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6981 6982 This uses the automatic analysis. 6983 6984 """ 6985 6986 # Cluster residues 6987 cluster_ids = [ 6988 ":52@N"] 6989 6990 # Load the data. 6991 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6992 6993 # The dispersion models. 6994 MODELS = [MODEL_R2EFF] 6995 6996 # The grid search size (the number of increments per dimension). 6997 GRID_INC = 4 6998 6999 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7000 MC_NUM = 3 7001 7002 # Model selection technique. 7003 MODSEL = 'AIC' 7004 7005 # Execute the auto-analysis (fast). 7006 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7007 OPT_FUNC_TOL = 1e-1 7008 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7009 OPT_MAX_ITERATIONS = 1000 7010 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7011 7012 result_dir_name = ds.tmpdir 7013 7014 # Make all spins free 7015 for curspin in cluster_ids: 7016 self.interpreter.relax_disp.cluster('free spins', curspin) 7017 # Shut them down 7018 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7019 7020 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7021 7022 # Run the analysis. 7023 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 7024 7025 # Check the graphs produced. 7026 graph_comb = [ 7027 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 7028 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 7029 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 7030 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 7031 ] 7032 7033 # Define expected folder names. 7034 result_folders = MODELS 7035 7036 # Assign spin_id. 7037 spin_id = ':52@N' 7038 7039 # Loop over result folders. 7040 for result_folder in result_folders: 7041 # Skip the model R2eff, which does not produce graphs. 7042 if result_folder == MODEL_R2EFF: 7043 continue 7044 7045 # Loop over graphs. 7046 for y_axis, x_axis, interpolate in graph_comb: 7047 # Determine file name: 7048 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7049 7050 # Make the file name. 7051 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7052 7053 # Get the file path. 7054 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 7055 7056 print("Testing file access to graph: %s"%file_path) 7057 self.assert_(access(file_path, F_OK)) 7058 7059 # Start testing all possible combinations of graphs. 7060 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 7061 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 7062 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 7063 7064 result_dir_name = ds.tmpdir 7065 7066 # Loop through all possible combinations of y_axis, x_axis and interpolation. 7067 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 7068 7069 for result_folder in result_folders: 7070 # Skip the model R2eff, which does not produce graphs. 7071 if result_folder == MODEL_R2EFF: 7072 continue 7073 7074 for y_axis in y_axis_types: 7075 for x_axis in x_axis_types: 7076 for interpolate in interpolate_types: 7077 # Determine file name: 7078 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7079 7080 # Make the file name. 7081 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7082 7083 # Write the curves. 7084 dir = result_dir_name+sep+result_folder 7085 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 7086 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 7087 7088 # Get the file path. 7089 file_path = get_file_path(file_name, dir) 7090 7091 # Test the plot file exists. 7092 print("Testing file access to graph: %s"%file_path) 7093 self.assert_(access(file_path, F_OK)) 7094 7095 # Now open, and compare content, line by line. 7096 file_prod = open(file_path) 7097 lines_prod = file_prod.readlines() 7098 file_prod.close() 7099 7100 # Define file to compare against. 7101 dir_comp = data_path+sep+result_folder 7102 file_path_comp = get_file_path(file_name, dir_comp) 7103 file_comp = open(file_path_comp) 7104 lines_comp = file_comp.readlines() 7105 file_comp.close() 7106 7107 # Assert number of lines is equal. 7108 self.assertEqual(len(lines_prod), len(lines_comp)) 7109 for j in range(len(lines_prod)): 7110 # Make the string test 7111 first_char = lines_prod[j][0] 7112 if first_char in ["@", "&"]: 7113 self.assertEqual(lines_prod[j], lines_comp[j]) 7114 else: 7115 # Split string in x, y, error. 7116 # The error would change per run. 7117 x_prod, y_prod, y_prod_err = lines_prod[j].split() 7118 x_comp, y_comp, y_comp_err = lines_comp[j].split() 7119 self.assertAlmostEqual(float(x_prod), float(x_comp)) 7120 self.assertAlmostEqual(float(y_prod), float(y_comp))
7121 7122
7124 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 7125 7126 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7127 7128 This uses the automatic analysis, with missing loading R1. 7129 7130 """ 7131 7132 # Cluster residues 7133 cluster_ids = [ 7134 ":13@N", 7135 ":15@N", 7136 ":16@N", 7137 ":25@N", 7138 ":26@N", 7139 ":28@N", 7140 ":39@N", 7141 ":40@N", 7142 ":41@N", 7143 ":43@N", 7144 ":44@N", 7145 ":45@N", 7146 ":49@N", 7147 ":52@N", 7148 ":53@N"] 7149 7150 # Load the data. 7151 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 7152 7153 # The dispersion models. 7154 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7155 7156 # The grid search size (the number of increments per dimension). 7157 GRID_INC = None 7158 7159 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7160 MC_NUM = 3 7161 7162 # Model selection technique. 7163 MODSEL = 'AIC' 7164 7165 # Execute the auto-analysis (fast). 7166 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7167 OPT_FUNC_TOL = 1e-25 7168 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7169 OPT_MAX_ITERATIONS = 10000000 7170 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7171 7172 result_dir_name = ds.tmpdir 7173 7174 # Make all spins free 7175 for curspin in cluster_ids: 7176 self.interpreter.relax_disp.cluster('free spins', curspin) 7177 # Shut them down 7178 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7179 7180 # Select only a subset of spins for global fitting 7181 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7182 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7183 7184 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7185 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7186 7187 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7188 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7189 7190 # Point to directory with R2eff values, with 2000 MC simulations. 7191 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" 7192 7193 r1_fit = True 7194 7195 # Run the analysis. 7196 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit) 7197 7198 # Verify the data. 7199 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7200 7201
7202 - def test_r2eff_read(self):
7203 """Test the operation of the relax_disp.r2eff_read user function.""" 7204 7205 # The path to the data files. 7206 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 7207 7208 # Read the sequence data. 7209 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 7210 7211 # The ID. 7212 id = 'test' 7213 7214 # Set up the metadata. 7215 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 7216 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7217 7218 # Try reading the file. 7219 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3) 7220 7221 # Check the global data. 7222 data = [ 7223 ['cpmg_frqs', {'test': 66.667}], 7224 ['cpmg_frqs_list', [66.667]], 7225 ['dispersion_points', 1], 7226 ['exp_type', {'test': 'SQ CPMG'}], 7227 ['exp_type_list', ['SQ CPMG']], 7228 ['spectrometer_frq', {'test': 800000000.0}], 7229 ['spectrometer_frq_count', 1], 7230 ['spectrometer_frq_list', [800000000.0]], 7231 ['spectrum_ids', ['test']] 7232 ] 7233 for name, value in data: 7234 # Does it exist? 7235 self.assert_(hasattr(cdp, name)) 7236 7237 # Check the object. 7238 obj = getattr(cdp, name) 7239 self.assertEqual(obj, value) 7240 7241 # Check the spin data. 7242 data = [ 7243 [1, 2.3035747e+04, 8.5467725e+01], 7244 [2, 9.9629762e+04, 2.8322033e+02], 7245 [3, 9.5663137e+04, 2.8632929e+02], 7246 [4, 1.7089893e+05, 3.1089428e+02], 7247 [5, 4.7323876e+04, 1.0084269e+02], 7248 [6, 2.0199122e+04, 1.0135220e+02], 7249 [7, 1.6655488e+05, 3.1609061e+02], 7250 [8, 9.0061074e+04, 1.9176585e+02], 7251 [10, 8.4726204e+04, 2.8898155e+02], 7252 [11, 1.5050233e+05, 4.3138029e+02], 7253 [12, 9.2998531e+04, 3.0440191e+02], 7254 [13, 1.6343507e+05, 3.3144097e+02], 7255 [14, 1.0137301e+05, 3.7314642e+02], 7256 [15, 8.3407837e+04, 1.6546473e+02], 7257 [16, 1.3819126e+05, 3.3388517e+02], 7258 [17, 1.1010490e+05, 3.5639222e+02], 7259 [18, 9.4324035e+04, 3.2343585e+02], 7260 [19, 1.1135179e+05, 3.0706671e+02], 7261 [20, 7.6339410e+04, 1.7377460e+02], 7262 [21, 6.2008453e+04, 1.7327150e+02], 7263 [22, 1.0590404e+05, 2.4814635e+02], 7264 [23, 1.0630198e+05, 2.3601100e+02], 7265 [24, 7.2996320e+04, 1.4952465e+02], 7266 [25, 9.5486742e+04, 2.7080766e+02], 7267 [26, 5.8067989e+04, 1.6820462e+02], 7268 [27, -1.7168510e+04, 2.2519560e+02], 7269 [28, 1.6891473e+05, 2.3497525e+02], 7270 [29, 9.4038555e+04, 2.0357593e+02], 7271 [30, 2.1386951e+04, 2.2153532e+02], 7272 [31, 9.3982899e+04, 2.0937056e+02], 7273 [32, 8.6097484e+04, 2.3868467e+02], 7274 [33, 1.0194337e+05, 2.7370704e+02], 7275 [34, 8.5683111e+04, 2.0838076e+02], 7276 [35, 8.6985768e+04, 2.0889310e+02], 7277 [36, 8.6011237e+04, 1.7498390e+02], 7278 [37, 1.0984097e+05, 2.7622998e+02], 7279 [38, 8.7017879e+04, 2.6547994e+02], 7280 [39, 9.1682649e+04, 5.2777676e+02], 7281 [40, 7.6370440e+04, 1.9873214e+02], 7282 [41, 9.1393531e+04, 2.4483824e+02], 7283 [42, 1.1017111e+05, 2.8020699e+02], 7284 [43, 9.4552366e+04, 3.4394150e+02], 7285 [44, 1.2858281e+05, 6.8449252e+02], 7286 [45, 7.4583525e+04, 1.9544210e+02], 7287 [46, 9.2087490e+04, 2.0491066e+02], 7288 [47, 9.7507255e+04, 2.5162839e+02], 7289 [48, 1.0033842e+05, 2.7566430e+02], 7290 [49, 1.3048305e+05, 2.6797466e+02], 7291 [50, 1.0546796e+05, 1.9304384e+02], 7292 [51, 9.3099697e+04, 2.0773311e+02], 7293 [52, 4.6863758e+04, 1.3169068e+02], 7294 [53, 6.1055806e+04, 1.5448477e+02], 7295 [55, 6.8629994e+04, 1.6868673e+02], 7296 [56, 1.1005552e+05, 2.1940465e+02], 7297 [57, 1.0572760e+05, 1.9768486e+02], 7298 [58, 1.1176950e+05, 3.0009610e+02], 7299 [59, 9.8758603e+04, 3.3803895e+02], 7300 [60, 9.9517201e+04, 3.5137994e+02], 7301 [61, 5.4357946e+04, 2.5896579e+02], 7302 [62, 1.0899978e+05, 2.8720371e+02], 7303 [63, 8.4549759e+04, 4.1401837e+02], 7304 [64, 5.5014550e+04, 2.1135781e+02], 7305 [65, 8.0569666e+04, 2.3249709e+02], 7306 [66, 1.2936610e+05, 3.5218725e+02], 7307 [67, 3.6438010e+04, 8.7924003e+01], 7308 [70, 3.8763157e+04, 1.3325040e+02], 7309 [71, 8.5711411e+04, 2.9316183e+02], 7310 [72, 3.3211541e+04, 1.2182123e+02], 7311 [73, 3.2070576e+04, 1.2305430e+02] 7312 ] 7313 for res_num, value, error in data: 7314 # Get the spin. 7315 spin = return_spin(spin_id=":%s"%res_num) 7316 7317 # Check the values. 7318 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 7319 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7320 7321
7322 - def test_r2eff_read_spin(self):
7323 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 7324 7325 # The path to the data files. 7326 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 7327 7328 # Generate the sequence. 7329 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 7330 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 7331 self.interpreter.spin.isotope('1H', spin_id='@H') 7332 self.interpreter.spin.isotope('15N', spin_id='@N') 7333 7334 # Build the experiment IDs. 7335 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 7336 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 7337 ids = [] 7338 for value in H_disp_points: 7339 ids.append('1H_CPMG_%s' % value) 7340 for value in N_disp_points: 7341 ids.append('15N_CPMG_%s' % value) 7342 print("\n\nThe experiment IDs are %s." % ids) 7343 7344 # Set up the metadata for the experiments. 7345 for id in ids: 7346 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 7347 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7348 for value in H_disp_points: 7349 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 7350 for value in N_disp_points: 7351 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 7352 7353 # Loop over the experiments. 7354 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 7355 # Try reading the file. 7356 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 7357 7358 # Check the global data. 7359 data = [ 7360 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}], 7361 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]], 7362 ['dispersion_points', 24], 7363 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}], 7364 ['exp_type_list', ['SQ CPMG']], 7365 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}], 7366 ['spectrometer_frq_count', 1], 7367 ['spectrometer_frq_list', [500000000.0]], 7368 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']] 7369 ] 7370 for name, value in data: 7371 # Does it exist? 7372 self.assert_(hasattr(cdp, name)) 7373 7374 # Check the object. 7375 obj = getattr(cdp, name) 7376 if not isinstance(data, dict): 7377 self.assertEqual(obj, value) 7378 7379 # Check the global dictionary data. 7380 else: 7381 for id in ids: 7382 self.assertEqual(obj[id], value[id]) 7383 7384 # Check the spin data. 7385 h_data = [ 7386 [ 67.0, 21.47924, 0.42958], 7387 [ 133.0, 16.73898, 0.33478], 7388 [ 267.0, 9.97357, 0.19947], 7389 [ 400.0, 8.23877, 0.24737], 7390 [ 533.0, 7.59290, 0.24263], 7391 [ 667.0, 7.45843, 0.24165], 7392 [ 800.0, 7.11222, 0.23915], 7393 [ 933.0, 7.40880, 0.24129], 7394 [1067.0, 6.55191, 0.16629], 7395 [1600.0, 6.72177, 0.23637], 7396 [2133.0, 7.09629, 0.23904], 7397 [2667.0, 7.14675, 0.23940] 7398 ] 7399 for disp_point, value, error in h_data: 7400 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7401 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 7402 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 7403 n_data = [ 7404 [ 50.0, 27.15767, 0.54315], 7405 [ 100.0, 26.55781, 0.53116], 7406 [ 150.0, 24.73462, 0.49469], 7407 [ 200.0, 20.98617, 0.41972], 7408 [ 250.0, 17.82442, 0.35649], 7409 [ 300.0, 15.55352, 0.31107], 7410 [ 350.0, 13.78958, 0.27579], 7411 [ 400.0, 12.48334, 0.24967], 7412 [ 500.0, 11.55724, 0.23114], 7413 [ 600.0, 10.53874, 0.21077], 7414 [ 700.0, 10.07395, 0.20148], 7415 [ 800.0, 9.62952, 0.19259], 7416 [ 900.0, 9.49994, 0.19000], 7417 [1000.0, 8.71350, 0.17427] 7418 ] 7419 for disp_point, value, error in n_data: 7420 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7421 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 7422 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7423 7424
7425 - def test_r2eff_fit_fixed_time(self):
7426 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 7427 7428 # Execute the script. 7429 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7430 7431
7432 - def test_read_r2eff(self):
7433 """Test the reading of a file containing r2eff values.""" 7434 7435 # Create the sequence data, and name the spins. 7436 self.interpreter.residue.create(1, 'Gly') 7437 self.interpreter.residue.create(2, 'Gly') 7438 self.interpreter.residue.create(3, 'Gly') 7439 7440 # Read the file. 7441 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4) 7442 7443 # Test the data. 7444 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 7445 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 7446 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7447 7448
7450 """Test speeding up grid search. Support requst sr #3151 U{https://gna.org/support/index.php?3151}. 7451 7452 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 7453 7454 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7455 'SOD1-WT' CPMG data to the CR72 dispersion model. 7456 7457 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7458 Data is for experiment at 25 degree Celcius. 7459 """ 7460 7461 # Base data setup. 7462 pipe_name = 'base pipe' 7463 pipe_type = 'relax_disp' 7464 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7465 select_spin_index = list(range(0, 1)) 7466 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7467 7468 # Generate r20 key. 7469 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7470 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7471 7472 ## Now prepare for MODEL calculation. 7473 MODEL = "CR72" 7474 7475 # Change pipe. 7476 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7477 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7478 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7479 7480 # Then select model. 7481 self.interpreter.relax_disp.select_model(model=MODEL) 7482 7483 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7484 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7485 7486 # Test result, for normal run. 7487 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7488 # Get the spin_params. 7489 spin_params = spin.params 7490 7491 # Defined fixed values for testing. 7492 if spin_id == ":10@N": 7493 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 7494 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 7495 7496 # Print out. 7497 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn)) 7498 7499 # Testing the r2 values for the different fields are not the same. 7500 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 7501 7502 # Test values are larger than 0. 7503 self.assert_(spin.r2[r20_key_600] > 0.0) 7504 self.assert_(spin.r2[r20_key_500] > 0.0) 7505 7506 # Loop over the experiment settings. 7507 r2eff_600 = [] 7508 r2eff_500 = [] 7509 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 7510 # Create the data key. 7511 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 7512 7513 # Extract the r2 eff data. 7514 r2eff = spin.r2eff[data_key] 7515 if frq == 599.8908617*1E6: 7516 r2eff_600.append(r2eff) 7517 elif frq == 499.862139*1E6: 7518 r2eff_500.append(r2eff) 7519 7520 # Sort values. 7521 r2eff_600.sort() 7522 r2eff_500.sort() 7523 7524 # Test values again. 7525 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 7526 print(r2eff_600) 7527 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 7528 print("") 7529 7530 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 7531 print(r2eff_500) 7532 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 7533 print("") 7534 7535 print("###########################################") 7536 print("Trying GRID SEARCH for minimum R2eff values") 7537 7538 ### Test just the Grid search. 7539 GRID_INC = 5 7540 7541 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7542 7543 ### Then test the value.set function. 7544 # Change pipe. 7545 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 7546 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7547 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7548 7549 # Then select model. 7550 self.interpreter.relax_disp.select_model(model=MODEL) 7551 7552 # Then set the standard parameter values. 7553 for param in spin_params: 7554 print("Setting standard parameter for param: %s"%param) 7555 self.interpreter.value.set(param=param, index=None) 7556 7557 # Test result, for normal run. 7558 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7559 # Print out. 7560 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn)) 7561 7562 # Testing the r2 values. 7563 self.assertEqual(spin.r2[r20_key_600], 10.00) 7564 self.assertEqual(spin.r2[r20_key_500], 10.00) 7565 self.assertEqual(spin.pA, 0.9) 7566 self.assertEqual(spin.dw, 1.0) 7567 self.assertEqual(spin.kex, 1000.0) 7568 7569 print("###########################################") 7570 print("Trying GRID SEARCH for standard R2eff values") 7571 7572 ### Test just the Grid search. 7573 GRID_INC = 5 7574 7575 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7576 7577 ### Run auto_analysis. 7578 # The grid search size (the number of increments per dimension). 7579 GRID_INC = 5 7580 7581 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7582 MC_NUM = 3 7583 7584 # Model selection technique. 7585 MODSEL = 'AIC' 7586 7587 # Execute the auto-analysis (fast). 7588 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7589 OPT_FUNC_TOL = 1e-1 7590 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7591 OPT_MAX_ITERATIONS = 1000 7592 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7593 7594 # Run the analysis. 7595 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
7596 7597
7598 - def test_show_apod_extract(self):
7599 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7600 7601 # The path to the data files. 7602 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7603 7604 # Define file name. 7605 file_name = '128_0_FT.ft2' 7606 7607 # Call function. 7608 get_output = show_apod_extract(file_name=file_name, dir=data_path) 7609 7610 # Define how output should look like. 7611 # The output from showApod differs slightly according to NMRPipe version. But 'Noise Std Dev' is the same. 7612 # Dont test lines which can differ. 7613 show_apod_ver = [ 7614 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name), 7615 'REMARK Automated Noise Std Dev in Processed Data: 8583.41', 7616 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558', 7617 '', 7618 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR', 7619 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e'] 7620 #'', 7621 #' X H1 800 2048 0.8107 3.7310 4.9903e-03 9.8043e-04 5.2684e-02', 7622 #' Y N15 128 256 0.7303 3.0331 3.1260e-02 7.8434e-03 1.3413e-01'] 7623 7624 for i, line in enumerate(show_apod_ver): 7625 line_ver = get_output[i] 7626 7627 print(line) 7628 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:': 7629 continue 7630 # Make the string test 7631 self.assertEqual(line, line_ver)
7632 7633
7634 - def test_show_apod_rmsd(self):
7635 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7636 7637 # The path to the data files. 7638 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7639 7640 # Define file name. 7641 file_name = '128_0_FT.ft2' 7642 7643 # Call function. 7644 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path) 7645 7646 # Assert. 7647 self.assertEqual(rmsd, 8583.41)
7648 7649
7651 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files.""" 7652 7653 # The path to the data files. 7654 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7655 7656 # Call function, and get all file names. 7657 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir) 7658 7659 # Loop over file_paths. 7660 for wfile_path in wfile_paths: 7661 # Open the file. 7662 get_data = extract_data(file=wfile_path) 7663 7664 # Extract line 0, column 0. 7665 test = float(get_data[0][0]) 7666 7667 # Assert. 7668 self.assertEqual(test, 8583.41)
7669 7670
7672 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file.""" 7673 7674 # The path to the data files. 7675 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7676 7677 # Define file name. 7678 file_name = '128_0_FT.ft2' 7679 7680 # Call function, and get file name. 7681 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir) 7682 7683 # Open the file. 7684 get_data = extract_data(file=wfile_path) 7685 7686 # Extract line 0, column 0. 7687 test = float(get_data[0][0]) 7688 7689 # Assert. 7690 self.assertEqual(test, 8583.41)
7691 7692
7694 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7695 7696 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7697 'SOD1-WT' CPMG data to the CR72 dispersion model. 7698 7699 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7700 Data is for experiment at 25 degree Celcius. 7701 7702 bug #21954 U{https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 7703 """ 7704 7705 # Base data setup. 7706 pipe_name = 'base pipe' 7707 pipe_type = 'relax_disp' 7708 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7709 select_spin_index = list(range(0, 1)) 7710 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7711 7712 # Define replicated 7713 repl_A = ['Z_A1', 'Z_A15'] 7714 repl_B = ['Z_B1', 'Z_B18'] 7715 7716 # Loop over spectrum ID, and sort them 7717 spectrum_ids_A = [] 7718 spectrum_ids_B = [] 7719 for spectrum_id in cdp.spectrum_ids: 7720 if "A" in spectrum_id: 7721 spectrum_ids_A.append(spectrum_id) 7722 elif "B" in spectrum_id: 7723 spectrum_ids_B.append(spectrum_id) 7724 7725 # To clean up old error analysis, delete attributes 7726 delattr(cdp, "var_I") 7727 delattr(cdp, "sigma_I") 7728 7729 # Perform error analysis 7730 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7731 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7732 7733 # Loop over spins, save errors to list 7734 Errors_A_B = [] 7735 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7736 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7737 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7738 Errors_A_B.append([A_err, B_err]) 7739 7740 # To clean up old error analysis, delete attributes 7741 delattr(cdp, "var_I") 7742 delattr(cdp, "sigma_I") 7743 7744 # Perform error analysis. Order is important 7745 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7746 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7747 7748 # Loop over spins, save errors to list 7749 Errors_B_A = [] 7750 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7751 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7752 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7753 Errors_B_A.append([A_err, B_err]) 7754 7755 # Make test for order of error 7756 for i in range(len(Errors_A_B)): 7757 Error_A_B = Errors_A_B[i] 7758 Error_B_A = Errors_B_A[i] 7759 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 7760 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 7761 7762 # Make further tests for fixed values 7763 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 7764 std_A_fix = 2785.7263335738567 7765 7766 for id_A in spectrum_ids_A: 7767 self.assertEqual(cdp.sigma_I[id_A], std_A) 7768 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 7769 7770 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 7771 std_B_fix = 4967.3772030667988 7772 7773 for id_B in spectrum_ids_B: 7774 self.assertEqual(cdp.sigma_I[id_B], std_B) 7775 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7776 7777
7778 - def test_sod1wt_t25_to_cr72(self):
7779 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7780 7781 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7782 'SOD1-WT' CPMG data to the CR72 dispersion model. 7783 7784 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7785 Data is for experiment at 25 degree Celcius. 7786 """ 7787 7788 # Base data setup. 7789 pipe_name = 'base pipe' 7790 pipe_type = 'relax_disp' 7791 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7792 select_spin_index = list(range(0, 2)) 7793 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7794 7795 # Generate r20 key. 7796 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7797 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7798 7799 ## Now prepare for MODEL calculation. 7800 MODEL = "CR72" 7801 7802 # Change pipe. 7803 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7804 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7805 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7806 7807 # Then select model. 7808 self.interpreter.relax_disp.select_model(model=MODEL) 7809 7810 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 7811 GRID_INC = 7 7812 7813 # Store grid and minimisations results. 7814 grid_results = [] 7815 mini_results = [] 7816 clust_results = [] 7817 7818 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7819 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7820 7821 # Deselect insignificant spins. 7822 self.interpreter.relax_disp.insignificance(level=1.0) 7823 7824 # Perform Grid Search. 7825 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7826 7827 # Store result. 7828 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7829 # Store grid results. 7830 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7831 7832 ## Now do minimisation. 7833 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7834 set_func_tol = 1e-9 7835 set_max_iter = 100000 7836 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7837 7838 # Store result. 7839 pA_values = [] 7840 kex_values = [] 7841 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7842 # Store minimisation results. 7843 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7844 7845 # Store pA values. 7846 pA_values.append(spin.pA) 7847 7848 # Store kex values. 7849 kex_values.append(spin.kex) 7850 7851 print("\n# Now print before and after minimisation.\n") 7852 7853 # Print results. 7854 for i in range(len(grid_results)): 7855 # Get values. 7856 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7857 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7858 7859 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7860 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7861 7862 ## Prepare for clustering 7863 # Change pipe. 7864 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 7865 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 7866 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 7867 7868 # Then select model. 7869 self.interpreter.relax_disp.select_model(model=MODEL) 7870 7871 # Define cluster id. 7872 cluster_id = 'clust' 7873 7874 # Loop over spins to cluster them. 7875 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7876 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 7877 7878 # Copy over values. 7879 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 7880 7881 # Test the median values is correct 7882 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7883 print(pA_values) 7884 # The the median pA value returned. 7885 self.assertEqual(median(pA_values), spin.pA) 7886 7887 # The the median kex value returned. 7888 self.assertEqual(median(kex_values), spin.kex) 7889 7890 ## Now do minimisation. 7891 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7892 7893 # Store result. 7894 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7895 # Store clust results. 7896 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7897 7898 # Store the outcome of the clustering minimisation. 7899 clust_pA = spin.pA 7900 clust_kex = spin.kex 7901 7902 print("\n# Now testing.\n") 7903 7904 # Define results 7905 test_res = {} 7906 test_res[':10@N'] = {} 7907 test_res[':10@N']['r2600'] = 18.429755324773360 7908 test_res[':10@N']['r2500'] = 16.981349161968630 7909 test_res[':10@N']['dw'] = 2.700755859433969 7910 test_res[':10@N']['pA'] = 0.971531659288657 7911 test_res[':10@N']['kex'] = 3831.766337047963134 7912 test_res[':11@N'] = {} 7913 test_res[':11@N']['r2600'] = 18.193409421115213 7914 test_res[':11@N']['r2500'] = 17.308838135567765 7915 test_res[':11@N']['dw'] = 2.706650302761793 7916 test_res[':11@N']['pA'] = 0.971531659288657 7917 test_res[':11@N']['kex'] = 3831.766337047963134 7918 7919 # Then make tests. 7920 for i in range(len(grid_results)): 7921 # Get values. 7922 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7923 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7924 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 7925 7926 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7927 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7928 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn)) 7929 7930 # Make tests. 7931 self.assertEqual(clust_pA, c_pA) 7932 self.assertEqual(clust_kex, c_kex) 7933 7934 # Test values. 7935 if c_spin_id in test_res: 7936 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 7937 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 7938 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 7939 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 7940 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
7941 7942 # Save disp graph to temp. 7943 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 7944 7945
7947 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 7948 7949 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7950 'SOD1-WT' CPMG data to the CR72 dispersion model. 7951 7952 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7953 Data is for experiment at 25 degree Celcius. 7954 """ 7955 7956 # Base data setup. 7957 pipe_name = 'base pipe' 7958 pipe_type = 'relax_disp' 7959 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7960 select_spin_index = list(range(0, 2)) 7961 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7962 7963 # Generate r20 key. 7964 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7965 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7966 7967 # Cluster everything, to analyse together. 7968 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 7969 7970 # Write input 7971 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 7972 7973 # Check the r2eff set files. 7974 print("\nChecking the R2eff input set files.") 7975 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 7976 7977 # First check file exists 7978 for dir, file in files: 7979 print(dir+sep+file) 7980 self.assert_(access(dir+sep+file, F_OK)) 7981 7982 # Define how files should look like 7983 data_set_600 = [ 7984 "60.8272464287\n", 7985 "0.06\n", 7986 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 7987 "# G10\n", 7988 " 33.333 26.53556078711 0.5236104771163\n", 7989 " 66.667 25.29735243318 0.48766574122\n", 7990 " 100 25.09470361403 0.4820438864671\n", 7991 " 133.333 25.15603274331 0.4837377286085\n", 7992 " 166.667 24.27213341753 0.4599457904395\n", 7993 " 200 24.00364120328 0.4529773198905\n", 7994 " 266.667 24.03511395168 0.4537880662536\n", 7995 " 300 23.04761040024 0.4291039120557\n", 7996 " 333.333 22.95530300787 0.4268745963972\n", 7997 " 400 23.06158810662 0.4294426293624\n", 7998 " 466.667 22.26799054092 0.4106809618644\n", 7999 " 533.333 21.99851418823 0.4045232104735\n", 8000 " 666.667 21.19651570955 0.3868136173831\n", 8001 " 833.333 20.30938498379 0.3682604887899\n", 8002 " 1000 20.28273252609 0.367719392568\n", 8003 "# D11\n", 8004 " 33.333 24.76520269878 0.5026475808706\n", 8005 " 66.667 24.8773107448 0.5058752916906\n", 8006 " 100 24.90357815239 0.5066348551479\n", 8007 " 133.333 23.7782506151 0.4751950583865\n", 8008 " 166.667 23.68548762076 0.4727017128631\n", 8009 " 200 23.58629651618 0.4700517377679\n", 8010 " 266.667 23.47734671187 0.4671601744044\n", 8011 " 300 24.08647493772 0.4835855560598\n", 8012 " 333.333 22.98314371029 0.4542918950801\n", 8013 " 400 22.80339361568 0.4497107885587\n", 8014 " 466.667 22.91634335366 0.4525833037874\n", 8015 " 533.333 22.59774140046 0.4445334311324\n", 8016 " 666.667 20.9177750759 0.4046955726046\n", 8017 " 833.333 20.71792550566 0.4002363835007\n", 8018 " 1000 19.54080006349 0.3751112751853\n", 8019 ] 8020 8021 # Check data_set_600 8022 file = open(files[0][0]+sep+files[0][1]) 8023 lines = file.readlines() 8024 file.close() 8025 self.assertEqual(len(data_set_600), len(lines)) 8026 for i in range(len(data_set_600)): 8027 # Make the string test 8028 self.assertEqual(data_set_600[i], lines[i]) 8029 8030 # Define how files should look like 8031 data_set_500 = [ 8032 "50.6846152368\n", 8033 "0.04\n", 8034 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8035 "# G10\n", 8036 " 50 22.28084307393 0.2944966344183\n", 8037 " 100 21.93494977761 0.2910362768307\n", 8038 " 150 21.09850032232 0.282892238351\n", 8039 " 200 20.86493960397 0.2806737853646\n", 8040 " 250 20.75287269752 0.2796178205016\n", 8041 " 300 20.25597152406 0.2750013546989\n", 8042 " 350 19.92172163467 0.2719555756504\n", 8043 " 400 19.97712052922 0.272457105051\n", 8044 " 450 19.46807010415 0.2678972122793\n", 8045 " 500 19.76875460947 0.2705774849203\n", 8046 " 550 19.39161367402 0.2672216964327\n", 8047 " 600 19.03949517697 0.2641417899694\n", 8048 " 650 19.12218812132 0.2648605059901\n", 8049 " 700 19.01037461457 0.2638893584683\n", 8050 " 800 18.83395162904 0.2623674321143\n", 8051 " 900 18.47529972436 0.2593123604687\n", 8052 " 1000 18.5252023121 0.2597343394038\n", 8053 "# D11\n", 8054 " 50 22.15403890237 0.3285588379827\n", 8055 " 100 21.80946781746 0.3247185598713\n", 8056 " 150 21.77715415505 0.324361526682\n", 8057 " 200 21.41647464235 0.3204122024881\n", 8058 " 250 21.17099940822 0.3177616325958\n", 8059 " 300 21.03740030577 0.3163316496664\n", 8060 " 350 20.95393648281 0.3154427665172\n", 8061 " 400 20.93311399332 0.315221543436\n", 8062 " 450 20.18219905222 0.3073848655291\n", 8063 " 500 19.93599065085 0.3048744697057\n", 8064 " 550 19.68475725452 0.3023424499113\n", 8065 " 600 19.33575433934 0.2988741928798\n", 8066 " 650 19.53915692194 0.3008886196853\n", 8067 " 700 19.2018754351 0.2975587767134\n", 8068 " 800 18.82360965368 0.2938866923878\n", 8069 " 900 18.71861761238 0.2928790380131\n", 8070 " 1000 17.95878049287 0.2857341721151\n", 8071 ] 8072 8073 # Check data_set_500 8074 file = open(files[1][0]+sep+files[1][1]) 8075 lines = file.readlines() 8076 file.close() 8077 self.assertEqual(len(data_set_500), len(lines)) 8078 for i in range(len(data_set_500)): 8079 # Make the string test 8080 self.assertEqual(data_set_500[i], lines[i]) 8081 8082 # Test local dir tests. This will be turned off in system test. 8083 turn_on_local_dir_test = False 8084 8085 if turn_on_local_dir_test: 8086 ## Now check to local folder with None argument. 8087 # Write input 8088 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 8089 8090 # Check the r2eff set files. 8091 print("\nChecking the R2eff input set files.") 8092 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 8093 8094 # First check file exists 8095 for dir, file in files: 8096 print(dir+sep+file) 8097 self.assert_(access(dir+sep+file, F_OK)) 8098 8099 ## Now check to local folder with dir argument. 8100 # Write input 8101 set_dir = "Test_ShereKhan" 8102 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 8103 8104 # Check the r2eff set files. 8105 print("\nChecking the R2eff input set files.") 8106 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 8107 8108 # First check file exists 8109 for dir, file in files: 8110 print(dir+sep+file) 8111 self.assert_(access(dir+sep+file, F_OK))
8112 8113
8114 - def test_sprangers_data_to_mmq_cr72(self, model=None):
8115 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 8116 8117 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period. 8118 """ 8119 8120 # Reset. 8121 self.interpreter.reset() 8122 8123 # Create the data pipe and load the base data. 8124 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8125 self.interpreter.state.load(data_path+sep+'r2eff_values') 8126 8127 # The model data pipe. 8128 model = 'MMQ CR72' 8129 pipe_name = "%s - relax_disp" % model 8130 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8131 self.interpreter.pipe.switch(pipe_name=pipe_name) 8132 8133 # Set the model. 8134 self.interpreter.relax_disp.select_model(model=model) 8135 8136 # Cluster everything. 8137 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8138 8139 # Copy the data. 8140 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8141 8142 # Alias the spins. 8143 spin135S = cdp.mol[0].res[0].spin[0] 8144 spin135F = cdp.mol[0].res[0].spin[1] 8145 spin137S = cdp.mol[0].res[1].spin[0] 8146 spin137F = cdp.mol[0].res[1].spin[1] 8147 8148 # The R20 keys. 8149 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 8150 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8151 8152 # Set the cluster specific parameters (only for the first spin). 8153 spin135S.pA = 0.836591763632 8154 spin135S.kex = 241.806525261 8155 8156 # Set the initial parameter values. 8157 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 8158 spin135S.dw = 0.583003118785 8159 spin135S.dwH = 0.0361441944301 8160 8161 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 8162 spin135F.dw = 0.805849745104 8163 spin135F.dwH = 0.0215791945715 8164 8165 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 8166 spin137S.dw = 0.688107568372 8167 spin137S.dwH = 0.0344463604043 8168 8169 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 8170 spin137F.dw = 0.94978299907 8171 spin137F.dwH = 1.4818877939e-07 8172 8173 # Low precision optimisation. 8174 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 8175 8176 # Printout. 8177 print("\n\nOptimised parameters:\n") 8178 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8179 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8180 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8181 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8182 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8183 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8184 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8185 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8186 print("\n # Set the cluster specific parameters (only for the first spin).") 8187 print(" spin135S.pA = %s" % spin135S.pA) 8188 print(" spin135S.kex = %s" % spin135S.kex) 8189 print("\n # Set the initial parameter values.") 8190 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 8191 print(" spin135S.dw = %s" % spin135S.dw) 8192 print(" spin135S.dwH = %s" % spin135S.dwH) 8193 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 8194 print(" spin135F.dw = %s" % spin135F.dw) 8195 print(" spin135F.dwH = %s" % spin135F.dwH) 8196 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 8197 print(" spin137S.dw = %s" % spin137S.dw) 8198 print(" spin137S.dwH = %s" % spin137S.dwH) 8199 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 8200 print(" spin137F.dw = %s" % spin137F.dw) 8201 print(" spin137F.dwH = %s" % spin137F.dwH) 8202 8203 # Checks for residue :135S. 8204 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 8205 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 8206 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 8207 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 8208 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 8209 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 8210 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 8211 8212 # Checks for residue :135F. 8213 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 8214 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 8215 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 8216 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 8217 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 8218 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 8219 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 8220 8221 # Checks for residue :137S. 8222 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 8223 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 8224 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 8225 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 8226 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 8227 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 8228 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 8229 8230 # Checks for residue :137F. 8231 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 8232 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 8233 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 8234 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 8235 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 8236 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 8237 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8238 8239
8240 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
8241 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 8242 8243 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period. 8244 """ 8245 8246 # Reset. 8247 self.interpreter.reset() 8248 8249 # Create the data pipe and load the base data. 8250 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8251 self.interpreter.state.load(data_path+sep+'r2eff_values') 8252 8253 # The model data pipe. 8254 model = 'NS MMQ 2-site' 8255 pipe_name = "%s - relax_disp" % model 8256 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8257 self.interpreter.pipe.switch(pipe_name=pipe_name) 8258 8259 # Set the model. 8260 self.interpreter.relax_disp.select_model(model=model) 8261 8262 # Cluster everything. 8263 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8264 8265 # Copy the data. 8266 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8267 8268 # Alias the spins. 8269 spin135S = cdp.mol[0].res[0].spin[0] 8270 spin135F = cdp.mol[0].res[0].spin[1] 8271 spin137S = cdp.mol[0].res[1].spin[0] 8272 spin137F = cdp.mol[0].res[1].spin[1] 8273 8274 # The R20 keys. 8275 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8276 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8277 8278 # Set the cluster specific parameters (only for the first spin). 8279 spin135S.pA = 0.847378444499757 8280 spin135S.kex = 264.055604934724329 8281 8282 # Set the initial parameter values. 8283 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 8284 spin135S.dw = 0.585574008745351 8285 spin135S.dwH = 0.000000000000002 8286 8287 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 8288 spin135F.dw = 0.856699277665748 8289 spin135F.dwH = 0.000000000582587 8290 8291 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 8292 spin137S.dw = 0.772904450844973 8293 spin137S.dwH = 0.183351478512970 8294 8295 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 8296 spin137F.dw = 0.984568590342831 8297 spin137F.dwH = 0.000000001993458 8298 8299 # Low precision optimisation. 8300 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1) 8301 8302 # Printout. 8303 print("\n\nOptimised parameters:\n") 8304 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8305 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8306 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8307 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8308 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8309 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8310 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8311 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8312 8313 # FIXME: Remove this temporary return and properly check the results. 8314 return 8315 8316 # Checks for residue :135S. 8317 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 8318 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 8319 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 8320 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 8321 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 8322 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 8323 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 8324 8325 # Checks for residue :135F. 8326 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 8327 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 8328 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 8329 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 8330 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 8331 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 8332 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 8333 8334 # Checks for residue :137S. 8335 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 8336 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 8337 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 8338 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 8339 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 8340 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 8341 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 8342 8343 # Checks for residue :137F. 8344 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 8345 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 8346 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 8347 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 8348 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 8349 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 8350 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8351 8352
8353 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
8354 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 8355 8356 # Setup the data. 8357 self.setup_tp02_data_to_ns_r1rho_2site() 8358 8359 # Alias the spins. 8360 spin1 = cdp.mol[0].res[0].spin[0] 8361 spin2 = cdp.mol[0].res[1].spin[0] 8362 8363 # The R20 keys. 8364 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8365 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8366 8367 # Checks for residue :1. 8368 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 8369 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 8370 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 8371 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 8372 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 8373 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 8374 8375 # Checks for residue :2. 8376 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 8377 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 8378 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 8379 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 8380 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 8381 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8382 8383
8384 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
8385 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 8386 8387 # Setup the data. 8388 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 8389 8390 # Alias the spins. 8391 spin1 = cdp.mol[0].res[0].spin[0] 8392 spin2 = cdp.mol[0].res[1].spin[0] 8393 8394 # The R20 keys. 8395 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8396 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8397 8398 # Checks for residue :1. 8399 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 8400 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 8401 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 8402 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 8403 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 8404 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 8405 8406 # Checks for residue :2. 8407 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 8408 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 8409 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 8410 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 8411 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 8412 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8413 8414
8415 - def test_tp02_data_to_mp05(self):
8416 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 8417 8418 # Fixed time variable and the models. 8419 ds.fixed = True 8420 ds.models = ['R2eff', 'MP05'] 8421 8422 # Execute the script. 8423 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8424 8425 # Switch back to the data pipe for the optimisation. 8426 self.interpreter.pipe.switch('MP05 - relax_disp') 8427 8428 # The equivalent MP05 parameters. 8429 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 8430 pA = [0.775055484521586, 0.500000000036595] 8431 kex = [1235.20361276079, 2378.31403454691] 8432 delta_omega = [7.08194146569694, 5.4083562844306] 8433 chi2 = [0.0370400968727768, 0.182141732163934] 8434 8435 # Alias the spins. 8436 spin1 = cdp.mol[0].res[0].spin[0] 8437 spin2 = cdp.mol[0].res[1].spin[0] 8438 8439 # The R20 keys. 8440 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8441 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8442 8443 # Printout. 8444 print("\n\nOptimised parameters:\n") 8445 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8446 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8447 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8448 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8449 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8450 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8451 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8452 8453 # Check each spin. 8454 spin_index = 0 8455 for spin, spin_id in spin_loop(return_id=True): 8456 # Printout. 8457 print("\nSpin %s." % spin_id) 8458 8459 # Check the fitted parameters. 8460 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8461 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8462 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8463 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8464 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8465 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8466 8467 # Increment the spin index. 8468 spin_index += 1
8469 8470
8471 - def test_tp02_data_to_tap03(self):
8472 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 8473 8474 # Fixed time variable and the models. 8475 ds.fixed = True 8476 ds.models = ['R2eff', 'TAP03'] 8477 8478 # Execute the script. 8479 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8480 8481 # Switch back to the data pipe for the optimisation. 8482 self.interpreter.pipe.switch('TAP03 - relax_disp') 8483 8484 # The equivalent TAP03 parameters. 8485 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 8486 pA = [0.775042569092891, 0.500000000229685] 8487 kex = [1235.20852748765, 2379.47085580169] 8488 delta_omega = [7.08176806468445, 5.40708372863538] 8489 chi2 = [0.0371366837083293, 0.182212857256044] 8490 8491 # Alias the spins. 8492 spin1 = cdp.mol[0].res[0].spin[0] 8493 spin2 = cdp.mol[0].res[1].spin[0] 8494 8495 # The R20 keys. 8496 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8497 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8498 8499 # Printout. 8500 print("\n\nOptimised parameters:\n") 8501 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8502 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8503 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8504 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8505 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8506 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8507 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8508 8509 # Switch to the 'MP05' model data pipe, then check for each spin. 8510 self.interpreter.pipe.switch('TAP03 - relax_disp') 8511 spin_index = 0 8512 for spin, spin_id in spin_loop(return_id=True): 8513 # Printout. 8514 print("\nSpin %s." % spin_id) 8515 8516 # Check the fitted parameters. 8517 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8518 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8519 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8520 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8521 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8522 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8523 8524 # Increment the spin index. 8525 spin_index += 1
8526 8527
8529 """Implementation of Task #7882 U{https://gna.org/task/?7882}: Implement Monte-Carlo simulation, where errors are generated with width of standard deviation or residuals""" 8530 8531 # First check that results are stored with minimisation, to make sure that Sum of Squares are stored (Chi2 without weighting) and degrees of freedom (dof) is stored. 8532 8533 # Load the results file from a clustered minimisation. 8534 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8535 self.interpreter.results.read(file_name) 8536 8537 # Get the spins, which was used for clustering. 8538 spins_cluster = cdp.clustering['sel'] 8539 spins_free = cdp.clustering['free spins'] 8540 8541 # For sanity check, calculate degree of freedom. 8542 cur_spin_id = spins_cluster[0] 8543 cur_spin = return_spin(cur_spin_id) 8544 8545 # Calculate total number of datapoins. 8546 N = len(spins_cluster) 8547 N_dp = N * len(cur_spin.r2eff) 8548 8549 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8550 N_par = cdp.spectrometer_frq_count * N + N + 1 + 1 8551 dof = N_dp - N_par 8552 8553 # Sanity check of parameters. 8554 print(N_par, N_dp) 8555 8556 # Number of MC 8557 mc_nr = 3 8558 8559 # Setup MC for errors generated from the distribution described by chi2 and degrees of freedom from best fit. 8560 self.interpreter.monte_carlo.setup(number=mc_nr) 8561 8562 # Create data. 8563 self.interpreter.monte_carlo.create_data(distribution="red_chi2") 8564 8565 # Setup MC again. 8566 self.interpreter.monte_carlo.setup(number=mc_nr) 8567 8568 # Create data, and set the fixed error value, without setting the correct distribution. 8569 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, fixed_error=1.) 8570 8571 # Setup MC again. 8572 self.interpreter.monte_carlo.setup(number=mc_nr) 8573 8574 # Create data, with fixed error distribution, but not setting the error value. 8575 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="fixed") 8576 8577 # Setup MC again. 8578 self.interpreter.monte_carlo.create_data(distribution="fixed", fixed_error=1.) 8579 8580 # Now select the R2eff model, and try again. Expect raising an error. 8581 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 8582 8583 # Setup MC again. 8584 self.interpreter.monte_carlo.setup(number=mc_nr) 8585 8586 # Create data, and assert failure. 8587 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="red_chi2") 8588 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, method="direct", distribution="red_chi2")
8589 8590
8591 - def x_test_task_7882_kex_conf(self):
8592 """Test related to Task #7882 U{https://gna.org/task/?7882}: Try making a confidence interval of kex. 8593 According to the regression book of Graphpad: U{http://www.graphpad.com/faq/file/Prism4RegressionBook.pdf}. 8594 Page 109-111. 8595 """ 8596 8597 # Load the results file from a clustered minimisation. 8598 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8599 self.interpreter.results.read(file_name) 8600 8601 # Get the spins, which was used for clustering. 8602 spins_cluster = cdp.clustering['sel'] 8603 spins_free = cdp.clustering['free spins'] 8604 8605 # For sanity check, calculate degree of freedom. 8606 cur_spin_id = spins_cluster[0] 8607 cur_spin = return_spin(cur_spin_id) 8608 8609 # Calculate total number of datapoins. 8610 Ns = len(spins_cluster) 8611 N_dp = Ns * len(cur_spin.r2eff) 8612 8613 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8614 N_par = cdp.spectrometer_frq_count * Ns + Ns + 1 + 1 8615 dof_fit = N_dp - N_par 8616 8617 # Assert values. 8618 self.assertEqual(Ns, 61) 8619 self.assertEqual(N_dp, 1952) 8620 self.assertEqual(N_par, 185) 8621 8622 # Confidence interval of kex. 8623 # The number of parameters to check is kex = 1. 8624 P = 1 8625 # Number of datapoints 8626 N = N_dp 8627 # The degrees of freedom for this confidence interval 8628 dof_conf = N - P 8629 8630 # The critical value of the F distribution with p-value of 0.05 for 95% confidence. 8631 # Can be calculated with microsoft excel: 8632 # F=FINV(0,05; P; dof_conf), F=FINV(0,05; P; dof_conf), F=FINV(0,05; 1; 1951)=3,846229551 8633 # Can also be calculated with: import scipy.stats; scipy.stats.f.isf(0.05, 1, 1951)=3.8462295505435562 8634 F = 3.8462295505435562 8635 # Then calculate the scaling of chi2, which is the weighted sum of squares of best fit. 8636 scale = F*P/dof_conf +1 8637 8638 # Get the sum of best fit. 8639 SSbest_fit = cur_spin.chi2 8640 SSbest_kex = cur_spin.kex 8641 8642 # Get the scaled sum of best fit 8643 SSall_fixed = SSbest_fit * scale 8644 8645 print(SSbest_fit, scale, SSall_fixed) 8646 8647 # Now generate a list of kex values to try. 8648 kex_cur = cur_spin.kex 8649 kex_list = linspace(kex_cur - 1500, kex_cur + 3000, 200) 8650 8651 chi2_list = [] 8652 8653 for kex in kex_list: 8654 self.interpreter.value.set(val=kex, param='kex') 8655 8656 # Calculate the chi2 values. 8657 self.interpreter.minimise.calculate(verbosity=0) 8658 8659 # Get the chi2 value 8660 chi2_cur = cur_spin.chi2 8661 print("kex=%3.2f, chi2=%3.2f"%(kex, chi2_cur), chi2_cur<SSall_fixed) 8662 8663 # Add to list 8664 chi2_list.append(chi2_cur) 8665 8666 # Now make to numpy array. 8667 chi2_list = asarray(chi2_list) 8668 8669 # Now make a selection mask based on the criteria. 8670 sel_mask = chi2_list < SSall_fixed 8671 8672 # Select values of kex, and chi2_list 8673 kex_sel = kex_list[sel_mask] 8674 chi2_sel = chi2_list[sel_mask] 8675 8676 # Now make plot 8677 print(SSbest_kex, SSbest_fit, SSall_fixed) 8678 print(kex_sel) 8679 print(chi2_sel) 8680 8681 if True: 8682 import matplotlib.pyplot as plt 8683 8684 plt.plot(kex_sel, chi2_sel, "bo") 8685 plt.plot(SSbest_kex, SSbest_fit, "g*") 8686 plt.show()
8687 8688
8689 - def test_tp02_data_to_tp02(self):
8690 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 8691 8692 # Fixed time variable. 8693 ds.fixed = True 8694 8695 # Execute the script. 8696 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8697 8698 # The original parameters. 8699 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 8700 pA = 0.7654321 8701 kex = 1234.56789 8702 delta_omega = [7.0, 9.0] 8703 8704 # The R20 keys. 8705 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8706 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8707 8708 # Switch to the 'TP02' model data pipe, then check for each spin. 8709 self.interpreter.pipe.switch('TP02 - relax_disp') 8710 spin_index = 0 8711 for spin, spin_id in spin_loop(return_id=True): 8712 # Printout. 8713 print("\nSpin %s." % spin_id) 8714 8715 # Check the fitted parameters. 8716 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8717 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8718 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8719 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 8720 8721 # Increment the spin index. 8722 spin_index += 1
8723 8724
8726 """System test of the value.write function to write intensities for an R1rho setup. 8727 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write. 8728 8729 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8730 """ 8731 8732 # Load the state. 8733 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8734 self.interpreter.state.load(statefile, force=True) 8735 8736 # Set filepaths. 8737 int_filepath = ds.tmpdir+sep+'int.out' 8738 8739 # Write out the intensity parameter file. 8740 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 8741 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 8742 8743 # Test the file exists. 8744 self.assert_(access(int_filepath, F_OK)) 8745 8746 # Open the files for testing. 8747 int_file = open(int_filepath, 'r') 8748 8749 # Loop over the intensity file to test values. 8750 for line in int_file: 8751 # Skip lines starting with #. 8752 if line[0] == "#": 8753 continue 8754 8755 # Split the line 8756 linesplit = line.split() 8757 8758 # Assume values 8759 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8760 self.assertEqual(linesplit[5], "115571.4") 8761 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8762 self.assertEqual(linesplit[5], "68377.52") 8763 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8764 self.assertEqual(linesplit[5], "9141.689") 8765 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8766 self.assertEqual(linesplit[5], "29123.77") 8767 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8768 self.assertEqual(linesplit[5], "58914.94") 8769 8770 # Close files 8771 int_file.close()
8772 8773
8775 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 8776 8777 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8778 """ 8779 8780 # Load the state. 8781 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8782 self.interpreter.state.load(statefile, force=True) 8783 8784 # Set filepaths. 8785 theta_filepath = ds.tmpdir+sep+'theta.out' 8786 8787 # Write out the theta parameter file. 8788 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 8789 8790 # Test the file exists. 8791 self.assert_(access(theta_filepath, F_OK)) 8792 8793 # Open the files for testing. 8794 theta_file = open(theta_filepath, 'r') 8795 8796 # Loop over the theta file to test values. 8797 for line in theta_file: 8798 # Skip lines starting with #. 8799 if line[0] == "#": 8800 continue 8801 # Print lines, not including newline character. 8802 print(line[:-1]) 8803 8804 # Split the line 8805 linesplit = line.split() 8806 8807 # Assume values 8808 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8809 self.assertNotEqual(linesplit[5], "None") 8810 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8811 self.assertNotEqual(linesplit[5], "None") 8812 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8813 self.assertNotEqual(linesplit[5], "None") 8814 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8815 self.assertNotEqual(linesplit[5], "None") 8816 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8817 self.assertNotEqual(linesplit[5], "None") 8818 8819 # Close files 8820 theta_file.close()
8821 8822
8824 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 8825 8826 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8827 """ 8828 8829 # Load the state. 8830 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8831 self.interpreter.state.load(statefile, force=True) 8832 8833 # Set filepaths. 8834 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 8835 8836 # Write out the w_eff parameter file. 8837 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 8838 8839 # Test the file exists. 8840 self.assert_(access(w_eff_filepath, F_OK)) 8841 8842 # Open the files for testing. 8843 w_eff_file = open(w_eff_filepath, 'r') 8844 8845 # Loop over the w_eff file to test values. 8846 for line in w_eff_file: 8847 # Skip lines starting with #. 8848 if line[0] == "#": 8849 continue 8850 # Print lines, not including newline character. 8851 print(line[:-1]) 8852 8853 # Split the line 8854 linesplit = line.split() 8855 8856 # Assume values 8857 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8858 self.assertNotEqual(linesplit[5], "None") 8859 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8860 self.assertNotEqual(linesplit[5], "None") 8861 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8862 self.assertNotEqual(linesplit[5], "None") 8863 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8864 self.assertNotEqual(linesplit[5], "None") 8865 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8866 self.assertNotEqual(linesplit[5], "None") 8867 8868 # Close files 8869 w_eff_file.close()
8870 8871
8873 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 8874 8875 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8876 """ 8877 8878 # Load the state. 8879 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 8880 self.interpreter.state.load(statefile, force=True) 8881 8882 # Set pipe name, bundle and type. 8883 pipe_name = 'base pipe' 8884 pipe_bundle = 'relax_disp' 8885 pipe_type = 'relax_disp' 8886 8887 # The path to the data files. 8888 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 8889 8890 # Deselect all spins 8891 self.interpreter.deselect.all() 8892 8893 # Specify spins to be selected. 8894 select_spin_ids = [ 8895 ":13@N", 8896 ":15@N", 8897 ":16@N", 8898 ":25@N", 8899 ":26@N", 8900 ":28@N", 8901 ":39@N", 8902 ":40@N", 8903 ":41@N", 8904 ":43@N", 8905 ":44@N", 8906 ":45@N", 8907 ":49@N", 8908 ":52@N", 8909 ":53@N"] 8910 8911 # Reverse the selection for the spins. 8912 for curspin in select_spin_ids: 8913 print("Selecting spin %s"%curspin) 8914 self.interpreter.deselect.reverse(spin_id=curspin) 8915 8916 # Read the R1 data 8917 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 8918 8919 # The dispersion models. 8920 MODELS = ['R2eff'] 8921 8922 # The grid search size (the number of increments per dimension). 8923 GRID_INC = 4 8924 8925 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 8926 MC_NUM = 3 8927 8928 # Model selection technique. 8929 MODSEL = 'AIC' 8930 8931 # Execute the auto-analysis (fast). 8932 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 8933 OPT_FUNC_TOL = 1e-1 8934 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 8935 OPT_MAX_ITERATIONS = 1000 8936 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 8937 8938 # Run the analysis. 8939 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 8940 8941 ## Check for file creation 8942 # Set filepaths. 8943 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 8944 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 8945 8946 # Test the files exists. 8947 self.assert_(access(theta_filepath, F_OK)) 8948 self.assert_(access(w_eff_filepath, F_OK)) 8949 8950 # Open the files for testing. 8951 theta_file = open(theta_filepath, 'r') 8952 theta_result = [ 8953 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 8954 "#\n", 8955 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 8956 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8957 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8958 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8959 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8960 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8961 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8962 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8963 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n", 8964 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8965 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n", 8966 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n", 8967 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8968 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8969 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8970 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8971 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8972 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n", 8973 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n", 8974 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8975 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n", 8976 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8977 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8978 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8979 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8980 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8981 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8982 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8983 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8984 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8985 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n", 8986 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n", 8987 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n", 8988 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8989 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n", 8990 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n", 8991 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n", 8992 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8993 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8994 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n", 8995 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8996 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8997 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n", 8998 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n", 8999 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9000 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9001 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9002 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9003 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9004 ] 9005 # Check the created theta file. 9006 lines = theta_file.readlines() 9007 for i in range(len(lines)): 9008 # Test lines starting with # 9009 if theta_result[i][0] == "#": 9010 self.assertEqual(theta_result[i], lines[i]) 9011 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9012 if theta_result[i] == lines[i]: 9013 self.assertEqual(theta_result[i], lines[i]) 9014 # If the line is not equal each other, make a slower comparison of values. 9015 else: 9016 # Print lines if they don't match. To help find differences. 9017 print(theta_result[i]) 9018 print(lines[i]) 9019 9020 # First test first 62 characters containing spin information 9021 self.assertEqual(theta_result[i][:62], lines[i][:62]) 9022 9023 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9024 theta_result_s = theta_result[i][62:].split()[::2] 9025 print(theta_result_s ) 9026 lines_s = lines[i][62:].split()[::2] 9027 print(lines_s) 9028 # Loop over the value elements 9029 for j in range(len(lines_s)): 9030 print(theta_result_s[j], lines_s[j]) 9031 # Assume a precision to digits. 9032 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 9033 9034 # Close file 9035 theta_file.close() 9036 9037 w_eff_file = open(w_eff_filepath, 'r') 9038 w_eff_result = [ 9039 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 9040 "#\n", 9041 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 9042 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9043 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9044 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9045 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9046 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9047 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9048 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9049 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n", 9050 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9051 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n", 9052 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n", 9053 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9054 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9055 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9056 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9057 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9058 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n", 9059 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n", 9060 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9061 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n", 9062 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9063 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9064 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9065 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9066 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9067 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9068 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9069 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9070 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9071 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n", 9072 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n", 9073 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n", 9074 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9075 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n", 9076 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n", 9077 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n", 9078 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9079 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9080 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n", 9081 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9082 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9083 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n", 9084 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n", 9085 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9086 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9087 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9088 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9089 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9090 ] 9091 # Check the created w_eff file. 9092 lines = w_eff_file.readlines() 9093 for i in range(len(lines)): 9094 # Test lines starting with # 9095 if w_eff_result[i][0] == "#": 9096 self.assertEqual(w_eff_result[i], lines[i]) 9097 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9098 if w_eff_result[i] == lines[i]: 9099 self.assertEqual(w_eff_result[i], lines[i]) 9100 # If the line is not equal each other, make a slower comparison of values. 9101 else: 9102 # Print lines if they don't match. To help find differences. 9103 print(w_eff_result[i]) 9104 print(lines[i]) 9105 9106 # First test first 62 characters containing spin information 9107 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 9108 9109 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9110 w_eff_result_s = w_eff_result[i][62:].split()[::2] 9111 print(w_eff_result_s ) 9112 lines_s = lines[i][62:].split()[::2] 9113 print(lines_s) 9114 # Loop over the value elements 9115 for j in range(len(lines_s)): 9116 print(w_eff_result_s[j], lines_s[j]) 9117 # Assume a precision to digits. 9118 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 9119 9120 # Close file 9121 w_eff_file.close()
9122 9123
9125 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 9126 9127 This follows Task 7822. 9128 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 9129 9130 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 9131 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 9132 """ 9133 9134 # Load the data. 9135 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 9136 9137 # Set pipe name, bundle and type. 9138 pipe_name = 'base pipe' 9139 pipe_bundle = 'relax_disp' 9140 pipe_type = 'relax_disp' 9141 9142 # Create the data pipe. 9143 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 9144 9145 file = data_path + '1_setup_r1rho_GUI.py' 9146 self.interpreter.script(file=file, dir=None) 9147 9148 # Deselect all spins. 9149 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 9150 9151 # Select one spin. 9152 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 9153 9154 # Set the model. 9155 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 9156 9157 # Check if intensity errors have already been calculated. 9158 check_intensity_errors() 9159 9160 # Do a grid search. 9161 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 9162 9163 # Set algorithm. 9164 min_algor = 'Newton' 9165 constraints = True 9166 if constraints: 9167 min_options = ('%s'%(min_algor),) 9168 #min_algor = 'Log barrier' 9169 min_algor = 'Method of Multipliers' 9170 scaling_matrix = assemble_scaling_matrix(scaling=True) 9171 9172 # Collect spins 9173 all_spin_ids = [] 9174 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9175 all_spin_ids.append(spin_id) 9176 9177 spins = spin_ids_to_containers(all_spin_ids[:1]) 9178 9179 # Get constraints 9180 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 9181 else: 9182 min_options = () 9183 A, b = None, None 9184 min_options = () 9185 sim_boot = 200 9186 scaling_list = [1.0, 1.0] 9187 9188 # Minimise. 9189 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 9190 9191 # Loop over old err attributes. 9192 err_attr_list = ['r2eff_err', 'i0_err'] 9193 9194 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9195 # Loop over old err attributes. 9196 for err_attr in err_attr_list: 9197 if hasattr(cur_spin, err_attr): 9198 delattr(cur_spin, err_attr) 9199 9200 # Collect the estimation data from boot. 9201 my_dic = {} 9202 param_key_list = [] 9203 est_keys = [] 9204 est_key = '-2' 9205 est_keys.append(est_key) 9206 spin_id_list = [] 9207 9208 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9209 # Add key to dic. 9210 my_dic[spin_id] = {} 9211 9212 # Add key for estimate. 9213 my_dic[spin_id][est_key] = {} 9214 9215 # Add spin key to list. 9216 spin_id_list.append(spin_id) 9217 9218 # Generate spin string. 9219 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9220 9221 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9222 # Generate the param_key. 9223 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9224 9225 # Append key. 9226 param_key_list.append(param_key) 9227 9228 # Add key to dic. 9229 my_dic[spin_id][est_key][param_key] = {} 9230 9231 values = [] 9232 errors = [] 9233 times = [] 9234 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 9235 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 9236 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 9237 times.append(time) 9238 9239 # Convert to numpy array. 9240 values = asarray(values) 9241 errors = asarray(errors) 9242 times = asarray(times) 9243 9244 r2eff = getattr(cur_spin, 'r2eff')[param_key] 9245 i0 = getattr(cur_spin, 'i0')[param_key] 9246 9247 R_m_sim_l = [] 9248 I0_m_sim_l = [] 9249 for j in range(sim_boot): 9250 if j in range(0, 100000, 100): 9251 print("Simulation %i"%j) 9252 # Start minimisation. 9253 9254 # Produce errors 9255 I_err = [] 9256 for j, error in enumerate(errors): 9257 I_error = gauss(values[j], error) 9258 I_err.append(I_error) 9259 # Convert to numpy array. 9260 I_err = asarray(I_err) 9261 9262 x0 = [r2eff, i0] 9263 model = Relax_fit_opt(num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 9264 9265 # Ref input. 9266 #def generic_minimise(func=None, dfunc=None, d2func=None, args=(), x0=None, min_algor=None, min_options=None, func_tol=1e-25, grad_tol=None, maxiter=1e6, A=None, b=None, l=None, u=None, c=None, dc=None, d2c=None, print_flag=0, print_prefix="", full_output=False): 9267 # l=l, u=u, c=c, dc=dc, d2c=d2c 9268 # l: Lower bound constraint vector (l <= x <= u). 9269 # u: Upper bound constraint vector (l <= x <= u). 9270 # c: User supplied constraint function. 9271 # dc: User supplied constraint gradient function. 9272 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0) 9273 9274 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 9275 R_m_sim_l.append(R_m_sim_j) 9276 I0_m_sim_l.append(I0_m_sim_j) 9277 9278 # Get stats on distribution. 9279 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 9280 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 9281 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 9282 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 9283 9284 # Estimate R2eff errors. 9285 self.interpreter.relax_disp.r2eff_err_estimate() 9286 9287 est_key = '-1' 9288 est_keys.append(est_key) 9289 9290 # Collect data. 9291 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9292 # Add key for estimate. 9293 my_dic[spin_id][est_key] = {} 9294 9295 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9296 # Generate the param_key. 9297 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9298 9299 # Add key to dic. 9300 my_dic[spin_id][est_key][param_key] = {} 9301 9302 # Get the value. 9303 # Loop over err attributes. 9304 for err_attr in err_attr_list: 9305 if hasattr(cur_spin, err_attr): 9306 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9307 else: 9308 get_err_attr = 0.0 9309 9310 # Save to dic. 9311 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9312 9313 9314 # Make Carlo Simulations number 9315 mc_number_list = list(range(0, 1000, 250)) 9316 9317 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim'] 9318 9319 # Loop over the Monte Carlo simulations: 9320 for number in mc_number_list: 9321 # First delete old simulations. 9322 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9323 # Loop over old err attributes. 9324 for err_attr in err_attr_list: 9325 if hasattr(cur_spin, err_attr): 9326 delattr(cur_spin, err_attr) 9327 9328 # Loop over the simulated attributes. 9329 for sim_attr in sim_attr_list: 9330 if hasattr(cur_spin, sim_attr): 9331 delattr(cur_spin, sim_attr) 9332 9333 self.interpreter.monte_carlo.setup(number=number) 9334 self.interpreter.monte_carlo.create_data() 9335 self.interpreter.monte_carlo.initial_values() 9336 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 9337 self.interpreter.eliminate() 9338 self.interpreter.monte_carlo.error_analysis() 9339 9340 est_key = '%i'%number 9341 est_keys.append(est_key) 9342 9343 # Collect data. 9344 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9345 # Add key for estimate. 9346 my_dic[spin_id][est_key] = {} 9347 9348 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9349 # Generate the param_key. 9350 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9351 9352 # Add key to dic. 9353 my_dic[spin_id][est_key][param_key] = {} 9354 9355 # Get the value. 9356 # Loop over err attributes. 9357 for err_attr in err_attr_list: 9358 if hasattr(cur_spin, err_attr): 9359 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9360 else: 9361 get_err_attr = 0.0 9362 9363 # Save to dic. 9364 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9365 9366 # Set what to extract. 9367 err_attr = err_attr_list[0] 9368 9369 # Define list with text. 9370 text_list = [] 9371 9372 # Now loop through the data. 9373 for spin_id in spin_id_list: 9374 for est_key in est_keys: 9375 # Define list to pickup data. 9376 r2eff_err_list = [] 9377 9378 for param_key in param_key_list: 9379 # Get the value. 9380 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 9381 9382 # Add to list. 9383 r2eff_err_list.append(r2eff_err) 9384 9385 # Sum the list 9386 sum_array = sum(array(r2eff_err_list)) 9387 9388 # Join floats to string. 9389 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 9390 9391 # Define print string. 9392 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 9393 text_list.append(text) 9394 9395 9396 # Now print. 9397 filepath = NamedTemporaryFile(delete=False).name 9398 # Open the files for testing. 9399 w_file = open(filepath, 'w') 9400 9401 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 9402 9403 for text in text_list: 9404 # Print. 9405 print(text) 9406 9407 # Write to file. 9408 w_file.write(text+"\n") 9409 9410 # Close files 9411 w_file.close() 9412 9413 print("Filepath is: %s"%filepath) 9414 print("Start 'gnuplot' and write:") 9415 print("set term dumb") 9416 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9417 9418
9419 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
9420 """Verification of test_r1rho_kjaergaard_missing_r1.""" 9421 9422 # Check the kex value of residue 52 9423 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 9424 9425 # Print results for each model. 9426 print("\n\n################") 9427 print("Printing results") 9428 print("################\n") 9429 for model in models: 9430 # Skip R2eff model. 9431 if model == MODEL_R2EFF: 9432 continue 9433 9434 # Switch to pipe. 9435 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9436 print("\nModel: %s" % (model)) 9437 9438 # Loop over the spins. 9439 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9440 # Generate spin string. 9441 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9442 9443 # Loop over the parameters. 9444 print("Optimised parameters for spin: %s" % (spin_string)) 9445 for param in cur_spin.params + ['chi2']: 9446 # Get the value. 9447 if param in ['r1', 'r2']: 9448 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 9449 # Generate the R20 key. 9450 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 9451 9452 # Get the value. 9453 value = getattr(cur_spin, param)[r20_key] 9454 9455 # Print value. 9456 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9457 9458 # Compare values. 9459 if spin_id == ':52@N': 9460 if param == 'r1': 9461 if model == MODEL_NOREX: 9462 if r2eff_estimate == 'direct': 9463 self.assertAlmostEqual(value, 1.46138805) 9464 elif r2eff_estimate == 'MC2000': 9465 self.assertAlmostEqual(value, 1.46328102) 9466 elif r2eff_estimate == 'chi2_pyt': 9467 self.assertAlmostEqual(value, 1.43820629) 9468 elif model == MODEL_DPL94: 9469 if r2eff_estimate == 'direct': 9470 self.assertAlmostEqual(value, 1.44845742) 9471 elif r2eff_estimate == 'MC2000': 9472 self.assertAlmostEqual(value, 1.45019848) 9473 elif r2eff_estimate == 'chi2_pyt': 9474 self.assertAlmostEqual(value, 1.44666512) 9475 elif model == MODEL_TP02: 9476 if r2eff_estimate == 'direct': 9477 self.assertAlmostEqual(value, 1.54354392) 9478 elif r2eff_estimate == 'MC2000': 9479 self.assertAlmostEqual(value, 1.54352369) 9480 elif r2eff_estimate == 'chi2_pyt': 9481 self.assertAlmostEqual(value, 1.55964020) 9482 elif model == MODEL_TAP03: 9483 if r2eff_estimate == 'direct': 9484 self.assertAlmostEqual(value, 1.54356410) 9485 elif r2eff_estimate == 'MC2000': 9486 self.assertAlmostEqual(value, 1.54354367) 9487 elif r2eff_estimate == 'chi2_pyt': 9488 self.assertAlmostEqual(value, 1.55967157) 9489 elif model == MODEL_MP05: 9490 if r2eff_estimate == 'direct': 9491 self.assertAlmostEqual(value, 1.54356416) 9492 elif r2eff_estimate == 'MC2000': 9493 self.assertAlmostEqual(value, 1.54354372) 9494 elif r2eff_estimate == 'chi2_pyt': 9495 self.assertAlmostEqual(value, 1.55967163) 9496 elif model == MODEL_NS_R1RHO_2SITE: 9497 if r2eff_estimate == 'direct': 9498 self.assertAlmostEqual(value, 1.41359221, 5) 9499 elif r2eff_estimate == 'MC2000': 9500 self.assertAlmostEqual(value, 1.41321968, 5) 9501 elif r2eff_estimate == 'chi2_pyt': 9502 self.assertAlmostEqual(value, 1.36303129, 5) 9503 9504 elif param == 'r2': 9505 if model == MODEL_NOREX: 9506 if r2eff_estimate == 'direct': 9507 self.assertAlmostEqual(value, 11.48392439) 9508 elif r2eff_estimate == 'MC2000': 9509 self.assertAlmostEqual(value, 11.48040934) 9510 elif r2eff_estimate == 'chi2_pyt': 9511 self.assertAlmostEqual(value, 11.47224488) 9512 elif model == MODEL_DPL94: 9513 if r2eff_estimate == 'direct': 9514 self.assertAlmostEqual(value, 10.15688372, 6) 9515 elif r2eff_estimate == 'MC2000': 9516 self.assertAlmostEqual(value, 10.16304887, 6) 9517 elif r2eff_estimate == 'chi2_pyt': 9518 self.assertAlmostEqual(value, 9.20037797, 6) 9519 elif model == MODEL_TP02: 9520 if r2eff_estimate == 'direct': 9521 self.assertAlmostEqual(value, 9.72654896, 6) 9522 elif r2eff_estimate == 'MC2000': 9523 self.assertAlmostEqual(value, 9.72772726, 6) 9524 elif r2eff_estimate == 'chi2_pyt': 9525 self.assertAlmostEqual(value, 9.53948340, 6) 9526 elif model == MODEL_TAP03: 9527 if r2eff_estimate == 'direct': 9528 self.assertAlmostEqual(value, 9.72641887, 6) 9529 elif r2eff_estimate == 'MC2000': 9530 self.assertAlmostEqual(value, 9.72759374, 6) 9531 elif r2eff_estimate == 'chi2_pyt': 9532 self.assertAlmostEqual(value, 9.53926913, 6) 9533 elif model == MODEL_MP05: 9534 if r2eff_estimate == 'direct': 9535 self.assertAlmostEqual(value, 9.72641723, 6) 9536 elif r2eff_estimate == 'MC2000': 9537 self.assertAlmostEqual(value, 9.72759220, 6) 9538 elif r2eff_estimate == 'chi2_pyt': 9539 self.assertAlmostEqual(value, 9.53926778, 6) 9540 elif model == MODEL_NS_R1RHO_2SITE: 9541 if r2eff_estimate == 'direct': 9542 self.assertAlmostEqual(value, 9.34531535, 5) 9543 elif r2eff_estimate == 'MC2000': 9544 self.assertAlmostEqual(value, 9.34602793, 5) 9545 elif r2eff_estimate == 'chi2_pyt': 9546 self.assertAlmostEqual(value, 9.17631409, 5) 9547 9548 # For all other parameters. 9549 else: 9550 # Get the value. 9551 value = getattr(cur_spin, param) 9552 9553 # Print value. 9554 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9555 9556 # Compare values. 9557 if spin_id == ':52@N': 9558 if param == 'phi_ex': 9559 if model == MODEL_DPL94: 9560 if r2eff_estimate == 'direct': 9561 self.assertAlmostEqual(value, 0.07599563) 9562 elif r2eff_estimate == 'MC2000': 9563 self.assertAlmostEqual(value, 0.07561937) 9564 elif r2eff_estimate == 'chi2_pyt': 9565 self.assertAlmostEqual(value, 0.12946061) 9566 9567 elif param == 'pA': 9568 if model == MODEL_TP02: 9569 if r2eff_estimate == 'direct': 9570 self.assertAlmostEqual(value, 0.88827040) 9571 elif r2eff_estimate == 'MC2000': 9572 self.assertAlmostEqual(value, 0.88807487) 9573 elif r2eff_estimate == 'chi2_pyt': 9574 self.assertAlmostEqual(value, 0.87746233) 9575 elif model == MODEL_TAP03: 9576 if r2eff_estimate == 'direct': 9577 self.assertAlmostEqual(value, 0.88828922) 9578 elif r2eff_estimate == 'MC2000': 9579 self.assertAlmostEqual(value, 0.88809318) 9580 elif r2eff_estimate == 'chi2_pyt': 9581 self.assertAlmostEqual(value, 0.87747558) 9582 elif model == MODEL_MP05: 9583 if r2eff_estimate == 'direct': 9584 self.assertAlmostEqual(value, 0.88828924, 6) 9585 elif r2eff_estimate == 'MC2000': 9586 self.assertAlmostEqual(value, 0.88809321) 9587 elif r2eff_estimate == 'chi2_pyt': 9588 self.assertAlmostEqual(value, 0.87747562) 9589 elif model == MODEL_NS_R1RHO_2SITE: 9590 if r2eff_estimate == 'direct': 9591 self.assertAlmostEqual(value, 0.94504369, 6) 9592 elif r2eff_estimate == 'MC2000': 9593 self.assertAlmostEqual(value, 0.94496541, 6) 9594 elif r2eff_estimate == 'chi2_pyt': 9595 self.assertAlmostEqual(value, 0.92084707, 6) 9596 9597 elif param == 'dw': 9598 if model == MODEL_TP02: 9599 if r2eff_estimate == 'direct': 9600 self.assertAlmostEqual(value, 1.08875840, 6) 9601 elif r2eff_estimate == 'MC2000': 9602 self.assertAlmostEqual(value, 1.08765638, 6) 9603 elif r2eff_estimate == 'chi2_pyt': 9604 self.assertAlmostEqual(value, 1.09753230, 6) 9605 elif model == MODEL_TAP03: 9606 if r2eff_estimate == 'direct': 9607 self.assertAlmostEqual(value, 1.08837238, 6) 9608 elif r2eff_estimate == 'MC2000': 9609 self.assertAlmostEqual(value, 1.08726698, 6) 9610 elif r2eff_estimate == 'chi2_pyt': 9611 self.assertAlmostEqual(value, 1.09708821, 6) 9612 elif model == MODEL_MP05: 9613 if r2eff_estimate == 'direct': 9614 self.assertAlmostEqual(value, 1.08837241, 6) 9615 elif r2eff_estimate == 'MC2000': 9616 self.assertAlmostEqual(value, 1.08726706, 6) 9617 elif r2eff_estimate == 'chi2_pyt': 9618 self.assertAlmostEqual(value, 1.09708832, 6) 9619 elif model == MODEL_NS_R1RHO_2SITE: 9620 if r2eff_estimate == 'direct': 9621 self.assertAlmostEqual(value, 1.56001812, 5) 9622 elif r2eff_estimate == 'MC2000': 9623 self.assertAlmostEqual(value, 1.55833321, 5) 9624 elif r2eff_estimate == 'chi2_pyt': 9625 self.assertAlmostEqual(value, 1.36406712, 5) 9626 9627 elif param == 'kex': 9628 if model == MODEL_DPL94: 9629 if r2eff_estimate == 'direct': 9630 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 9631 elif r2eff_estimate == 'MC2000': 9632 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 9633 elif r2eff_estimate == 'chi2_pyt': 9634 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 9635 elif model == MODEL_TP02: 9636 if r2eff_estimate == 'direct': 9637 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 9638 elif r2eff_estimate == 'MC2000': 9639 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 9640 elif r2eff_estimate == 'chi2_pyt': 9641 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 9642 elif model == MODEL_TAP03: 9643 if r2eff_estimate == 'direct': 9644 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 9645 elif r2eff_estimate == 'MC2000': 9646 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 9647 elif r2eff_estimate == 'chi2_pyt': 9648 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 9649 elif model == MODEL_MP05: 9650 if r2eff_estimate == 'direct': 9651 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 9652 elif r2eff_estimate == 'MC2000': 9653 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 9654 elif r2eff_estimate == 'chi2_pyt': 9655 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 9656 elif model == MODEL_NS_R1RHO_2SITE: 9657 if r2eff_estimate == 'direct': 9658 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6) 9659 elif r2eff_estimate == 'MC2000': 9660 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 9661 elif r2eff_estimate == 'chi2_pyt': 9662 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 9663 9664 elif param == 'chi2': 9665 if model == MODEL_NOREX: 9666 if r2eff_estimate == 'direct': 9667 self.assertAlmostEqual(value, 848.42016907, 5) 9668 elif r2eff_estimate == 'MC2000': 9669 self.assertAlmostEqual(value, 3363.95829122, 5) 9670 elif r2eff_estimate == 'chi2_pyt': 9671 self.assertAlmostEqual(value, 5976.49946726, 5) 9672 elif model == MODEL_DPL94: 9673 if r2eff_estimate == 'direct': 9674 self.assertAlmostEqual(value, 179.47041241) 9675 elif r2eff_estimate == 'MC2000': 9676 self.assertAlmostEqual(value, 710.24767560) 9677 elif r2eff_estimate == 'chi2_pyt': 9678 self.assertAlmostEqual(value, 612.72616697, 5) 9679 elif model == MODEL_TP02: 9680 if r2eff_estimate == 'direct': 9681 self.assertAlmostEqual(value, 29.33882530, 6) 9682 elif r2eff_estimate == 'MC2000': 9683 self.assertAlmostEqual(value, 114.47142772, 6) 9684 elif r2eff_estimate == 'chi2_pyt': 9685 self.assertAlmostEqual(value, 250.50838162, 5) 9686 elif model == MODEL_TAP03: 9687 if r2eff_estimate == 'direct': 9688 self.assertAlmostEqual(value, 29.29050673, 6) 9689 elif r2eff_estimate == 'MC2000': 9690 self.assertAlmostEqual(value, 114.27987534) 9691 elif r2eff_estimate == 'chi2_pyt': 9692 self.assertAlmostEqual(value, 250.04050719, 5) 9693 elif model == MODEL_MP05: 9694 if r2eff_estimate == 'direct': 9695 self.assertAlmostEqual(value, 29.29054301, 6) 9696 elif r2eff_estimate == 'MC2000': 9697 self.assertAlmostEqual(value, 114.28002272) 9698 elif r2eff_estimate == 'chi2_pyt': 9699 self.assertAlmostEqual(value, 250.04077478, 5) 9700 elif model == MODEL_NS_R1RHO_2SITE: 9701 if r2eff_estimate == 'direct': 9702 self.assertAlmostEqual(value, 34.44010543, 6) 9703 elif r2eff_estimate == 'MC2000': 9704 self.assertAlmostEqual(value, 134.14368365) 9705 elif r2eff_estimate == 'chi2_pyt': 9706 self.assertAlmostEqual(value, 278.55121388, 5) 9707 9708 9709 # Print the final pipe. 9710 model = 'final' 9711 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9712 print("\nFinal pipe") 9713 9714 # Loop over the spins. 9715 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9716 # Generate spin string. 9717 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9718 9719 # Loop over the parameters. 9720 print("Optimised model for spin: %s" % (spin_string)) 9721 param = 'model' 9722 9723 # Get the value. 9724 value = getattr(cur_spin, param) 9725 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 9726 9727 9728 ### Now check some of the written out files. 9729 file_names = ['r1rho_prime', 'r1'] 9730 9731 for file_name_i in file_names: 9732 9733 # Make the file name. 9734 file_name = "%s.out" % file_name_i 9735 9736 # Get the file path. 9737 file_path = get_file_path(file_name, result_dir_name + sep + model) 9738 9739 # Test the file exists. 9740 print("Testing file access to: %s"%file_path) 9741 self.assert_(access(file_path, F_OK)) 9742 9743 # Now open, and compare content, line by line. 9744 file_prod = open(file_path) 9745 lines_prod = file_prod.readlines() 9746 file_prod.close() 9747 9748 # Loop over the lines. 9749 for i, line in enumerate(lines_prod): 9750 # Make the string test 9751 line_split = line.split() 9752 9753 # Continue for comment lines. 9754 if line_split[0] == "#": 9755 print(line), 9756 continue 9757 9758 # Assign the split of the line. 9759 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 9760 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 9761 9762 if res_num == '52': 9763 # Assert that the value is not None. 9764 self.assertNotEqual(val, 'None')
9765